BERARM BERARM - 5 months ago 23
JSON Question

How to get json key on nodejs

var temp = '{"name":"abc","0_1":"padforn"}';
console.log(JSON.parse(temp).name);
console.log(JSON.parse(temp).0_1);


The 'temp' variable has two keys.
Please How to get the value use key '0_1' ?

Answer

You can access it with JSON.parse(temp)['0_1'] as Rohit says. Note that in order to use dot notation, the identifier cannot start with a number.

Property Accesors

In this code, property must be a valid JavaScript identifier, i.e. a sequence of alphanumerical characters, also including the underscore ("_") and dollar sign ("$"), that cannot start with a number. For example, object.$1 is valid, while object.1 is not.

Comments