Reputation: 195
I am trying to get a list of ID from a JSON file.
So far, the only way to access the "id" object is by using this:
console.log(photos.photosets.photoset[0].id);
As you might tell, it only gives me the correct ID of the first item.
If I try this, it gives me an "undefined":
console.log(photos.photosets.photoset.id);
Upvotes: 1
Views: 55
Reputation: 193261
You will need to iterate array of photoset
's and produce new array of ids from it. Array.prototype.map is convenient in this case:
var ids = photos.photosets.photoset.map(function(obj) {
return obj.id;
});
Upvotes: 1
Reputation: 4017
No Angular, just JavaScript.
for (i = 0; i < photos.photosets.length; i++) {
console.log(photos.photosets.photoset[i].id
}
Upvotes: 1