user1400915 user1400915 - 7 months ago 12
Javascript Question

Accessing dynamic keys from a json object of an array

I need to access keys of a json object which was created dynamically . The array structure is:

self.arrayObj : Array[2]
>0:Object
>Display1
->InnerObjects
>__proto
>1:Object
>Display2
-->InnerObjects


Key is "Display1" and value is object. This key is dynamic and not fixed . How can I access the Key string from array above.

The output I am expecting as : "Display1" and "Display2"

Answer

try this

var keys = [];//final output of all key names

arrayObj.forEach(function(val){
  keys.concat(Object.keys(val));
});

keys now has all the dynamic property names.

Comments