0

Ex:

{
  "123": [
     ...stuff
  ]
}

How do I call "123" in a jquery without returning an error?

I've tried:

$.getJSON('insert-url-here').then(function (data) { console.log(data.123.length) }

but it doesn't work.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
doc biz
  • 9
  • 2

1 Answers1

0

Use square bracket notation:

const data = {
  "123": [1, 2, 3]
}

console.log(data[123].length);

Or since it's technically a string:

const data = {
  "123": [1, 2, 3]
}

console.log(data["123"].length);
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79