How can I access the attributes of this object in javascript?

1

I am rendering configurations in an app, so from ajax I get this object.

When I try to read it I can not because I do not know what the syntax is for doing it.

res.data.0-MenuComponent
res.data.'0-MenuComponent'

try with those two I have equal parseando the this way

res.data.String('0-MenuComponent')

but it returns an error to me.

    
asked by Jorge Alberto Ortega Ceja 27.09.2018 в 23:40
source

1 answer

3

The JSON key is violating the rules of creation

  

Choose meaningful property names. Property names must conform to the   following guidelines:

     

Property names should be meaningful names with defined semantics.   Property names must be camel-cased, ascii strings. The first character   must be a letter, an underscore (_) or a dollar sign ($). Subsequent   characters can be a letter, a digit, an underscore, or a dollar sign.   Reserved JavaScript keywords should be avoided (A list of reserved   JavaScript keywords can be found below).

JSON Rules

Now to solve what you have now you can do the following:

res["data"]["0-MenuComponent"]

Always use indexes, as the rule says, a digit is not supported with the semantics you are trying to implement.

    
answered by 28.09.2018 в 00:23