Hi, I see the need to obtain the key name of a Json in javascript, for example given this:
var myVar = { test: {typeA: '501', typeB : '502' } };
Get the name of 'test'
Hi, I see the need to obtain the key name of a Json in javascript, for example given this:
var myVar = { test: {typeA: '501', typeB : '502' } };
Get the name of 'test'
You can also use for...in :
EDIT:
I had to edit the answer since there were changes in the original question :
Basically what can be done is to use the Object.keys (Documentation in English) to obtain the desired values, for example:
based on @aldanux's answer
in the second example I show the values 501, 502...
I show you two very simple ways to get the test property in Javascript. One way is with a for and the other with Object.keys
Another option to what you request with map of
Javascript