Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get json objects attribute using javascript

Beginner at both JSON and javascript. I need a way to return the key subAttributeOne it self from a list of object instead of his value.

Following is example of a list,

var list = 
[
   {
   attribute1: "value",
   attribute2:[{subAttributeOne:"value",subAttributeTwo:"value"},{}]
   },
   //other objects
   {..}
]

I have tried following,

list[0].attribute2[1].subAttributeOne

it returns value but the result I need is subAttributeOne

like image 637
h.alaoui Avatar asked Aug 24 '16 08:08

h.alaoui


1 Answers

With this:

Object.keys(list[0].attribute2[0])

you get

['subAttributeOne', 'subAttributeTwo']
like image 68
gianlucatursi Avatar answered Nov 14 '22 23:11

gianlucatursi