0

I have json data and I want to get a specific object from the data. When I print data._embedded.artworks[0]._links.thumbnail in the console, I'm able to get the first thumbnail.

I'm wondering how I get all of the thumbnails. I tried

for (var key in data) {
    console.log(data._embedded.artworks[0]._links.thumbnail);
}

But here I also just get the thumbnails from the first id. I tried artworks[key] but I was not able to access other methods of the json data such as _links.

How would I loop through the json data to pull out all of the thumbnails?

2
  • data._embedded.artworks.map(link => console.log(link.thumbnail)) Commented Jul 29, 2019 at 0:19
  • @MoisheSchwartz .forEach is better so this, as you are not actually mapping Commented Jul 29, 2019 at 0:25

1 Answer 1

3

You are looping over data. You need to loop over data._emebedded.artworks. Try:

var art = data._embedded.artworks;
art.forEach(function(o){
  console.log(o._links.thumbnail);
});
Sign up to request clarification or add additional context in comments.

Comments

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.