0

I have the following JSON format:

Object {person: Array[10]}

I want to get the name called person.

I don't want to get the inner content just I want the name called person to store it in a variable.

How can I achieve this?

1
  • It would be clearer if you used correct terminology: person here is a "key". Commented Apr 18, 2015 at 6:00

1 Answer 1

1

According to MDN you can do this like this, assuming your object is stored in a variable named obj:

var keys = Object.keys(obj);
var person = keys[0];

Or another approach:

for ( prop in obj ) {
   // prop is the key name.
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.