How to get the name of the array in json data using JavaScript -
i have json object comes javascript api call:
{ "myarray": [ { "version": 5, "permissionmask": 1 }, { "version": 126, "permissionmask": 1 } ] }
how can access name of array (i.e myarray
) in javascript. need use name of array determine flow later on.
object.keys(data)[0] # => "myarray"
a terminology note: solution assumes have javascript object. might have json string, in case solution:
object.keys(json.parse(data))[0] # => "myarray"
however, "json object", in javascript, 1 - 1 used now, has json.parse
, json.stringify
methods. have not json object except perhaps in trivial interpretation of second case, values in javascript objects, including strings.
Comments
Post a Comment