Getting data from auxiliary JSON array in javascript where id starts with integer

I need to skip something simple, but I'm having trouble getting data from a JSON array response. I can access objects with identifiers starting with letters, but not with those starting with numbers.

For example, I can access

data.item[0].specs.overview.details

But I can’t access

data.item[0].specs.9a99.details
+3
source share
5 answers

Use parenthesis designation

i.e:

data.item[0].specs["9a99"].details
+5
source

, . :

 data.item[0].specs["9a99"].details
+5

Try it,

data.items[0].specs["9a99"].details
+2
source

A variable name in javascript cannot begin with a digit. This is the reason why it does not work.

+2
source

Javascript does not like variables or identifiers starting with a number, this link states that only:

Any variable name has to start with
_ (underscore) 
$ (currency sign) 
a letter from [a-z][A-Z] range 
Unicode letter in the form \uAABB (where AA and BB are hex values)

are valid first characters.

+2
source

Source: https://habr.com/ru/post/1742717/


All Articles