h.alaoui h.alaoui - 1 year ago 158
JSON Question

how to get json objects attribute using javascript

Beginner at JSON and javascript. I need a help to get return subAttributeOne from a list of object. I don't want it's value but the string subAttributeOne.

Following is example of list,

var list =
attribute1: "value",
//other objects

I have tried following,


it returns
but the result I need is

Answer Source

If you want keys from an object you can use object.keys that will bring back all the keys, but to define its position, in your case you can use like below:


But the [0] doesn't work like an index because properties order in objects is not guarantee in JavaScript. To learn more about this I recommand you to read about : Does JavaScript Guarantee Object Property Order?

In this link you will find the definition of an Object from ECMAScript Third Edition:

4.3.3 Object

An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download