Imagine we have this JSON:
{ "A" : {"A1": "1" } }
How can I extract the actual index A1 ?
So that I can use it in JS like:
var index = "A1";
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
edit — in case you mean, “How can I extract the value at index A1″, then you’d just use the dot or bracket operators:
or
Else see below.
You can iterate through the property names of an object with the
for ... inloop:The loop will also include properties from the prototype chain, so you can avoid that (if you want) with a function called
hasOwnProperty:Newer browsers support a way to get the property names as an array:
That list will only include “own” properties; that is, those for which
hasOwnProperty()would returntrue.Finally, there are ways that properties can be defined such that they’re not “enumerable”. Usually when that’s done, you would generally not want to see them in
for ... inanyway.