I have a javascript array written like this…
var json = [
{"id":"1", "title":"Test 1", "comment":"This is the first test"},
{"id":"2", "title":"Test 2", "comment":"This is the second test"}
];
what I am trying to do is get each one of the ids.
I have been trying this
for(x in json[0]){
alert(x.id);
}
But no luck, can someone point me in the right direction? Please and thank you 🙂
xin your example is giving you the indexes of you array, not the objects. You could do:but to loop through an array you’re really better off with a “regular” for loop