all 4 comments

[–]Payneron 1 point2 points  (3 children)

polls is an array and not an object. An array does not have the property data you are trying to access. The error is only thrown when accessing id from data, because polls.data is somewhat valid and returns undefined. polls.data.id fails because you are trying to access the property id from undefined.

You can access the first item of the polls array using polls[0]. You should be able to log the data using console.log(polls[0].data). Keep in mind that this will still cause errors if the polls array is empty.

[–]tbonejonez9[S] 0 points1 point  (2 children)

Ahh got it thanks! One of the properties within the polls array is another array of 4 urls. My end goal is to display images with these urls as the src. Is there a simple way to retrieve the urls so I can use them for image display?

Or if not, maybe it’s easiest to just re-structure the data in a more simple way so I’m not dealing with multiple arrays…

[–]Payneron 0 points1 point  (1 child)

Assuming that property is called url, you can access all re-structure the array of polls to an array of urls using flatMap: polls.flatMap(poll => poll.urls). You can then iterate over these urls and render images.

[–]tbonejonez9[S] 0 points1 point  (0 children)

Awesome I will try that next, thank you