How to convert string into array of objects in javascript? -
i have data shown below of string type
"[ { name: "robert baratheon", birthday: "12/02/1965" }, { name: "daario naharis", birthday: "12/02/1985" }, { name: "viserys targaryen", birthday: "12/06/1984" } ]"
i want convert array of objects, when use json.parse
or eval
giving me this
[object, object, object]
but don't want this, want remove double quotes can access array.
[ { name: "robert baratheon", birthday: "12/02/1965" }, { name: "daario naharis", birthday: "12/02/1985" }, { name: "viserys targaryen", birthday: "12/06/1984" } ]
when use json.parse(string)
in fact parse string of json object. in case, array of objects.
you can access object via
var mylist = json.parse(string) mylist[0] //this give first item in list console.log(mylist[0].name) //outputs robert baratheon console
Comments
Post a Comment