1

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);
1
  • there is no question here. and it is also unclear how this relates to angular. Commented Jul 24, 2015 at 19:05

2 Answers 2

1

No Angular, just JavaScript.

for (i = 0; i < photos.photosets.length; i++) {
 console.log(photos.photosets.photoset[i].id
}
Sign up to request clarification or add additional context in comments.

Comments

1

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;
});

1 Comment

...so that way, I can use it from my factory into a controller? That's what I'm aiming for, to replace ID's in a url by those from the Json...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.