google chrome - How can i list the values of a Node in JSON ? -
say, have json has array of "topics"
need list "created_at" values of topics
without other data , using chrome console
p.s : i'm using jsonview
you can loop through objects in array , access property created_at
.
example
var json = { all_topics: [{ "created_at:" "2016-08-08t10:22:03.123z", "name": "topic1" }, { "created_at": "2016-08-08t11:43:06.963z", "name": "topic2" }] } (var topic of json.all_topics) { console.log(topic.created_at); }
you can use json.stringify
turn javascript object json string, , json.parse
turn json string javascript object.
var jsonstring = json.stringify(json); ==> {"all_topics":[{"created_at":"2016-08-08t10:22:03.123z","name":"topic1"},{"created_at":"2016-08-08t11:43:06.963z","name":"topic2"}]} var jsonobj = json.parse(jsonstring); ==> object {all_topics: array[2]}
alternatively, return new array filtered property using array.prototype.map
:
var topics = json.all_topics.map(function(obj){ return obj.created_at; }); ==> ["2016-08-08t10:22:03.123z", "2016-08-08t11:43:06.963z"]
Comments
Post a Comment