I am calling an API and successfully getting back an array like this:
[ {
"absmag" : "4.85",
"speed" : "0",
"colorb_v" : "0.65",
"label" : "Sun",
"appmag" : "-26.72",
"distance_light_years" : "0",
"id" : "53794",
"hipnum" : "0",
"vy" : "0",
"updated_at" : "49:09.3",
"vx" : "0",
"vz" : "0",
"texnum" : "1",
"plxerr" : "0",
"created_at" : "49:09.3",
"plx" : "0",
"dcalc" : "0",
"z" : "0",
"luminosity" : "0.8913",
"y" : "0",
"x" : "0"
}
]
How can I reference each of these lines? I'd like to do something like:
var database = xml.responseText;
console.log(database.label);
xml.responseText
is an array, you need to access on the the good index before showlabel
:If the response is a string, you need to parse the response before use it :
Edit :
If your array has more than one index, you can use a foreach loop :