I am making an API call:
const idVal = 59
APIGet(resource, params)
.then((res) => {
console.log(res.data.body)
setData(res.data.body)
})
console.log(res.data.body) returns:
Array [ {…} ]
0: Object { Id: 978, UniqueHash: "uZIYvh", Title: "testval", … }
Id: 978
Title: "Title for product"
UniqueHash: "uYvh"
organizers: Array [ {…}, {…} ]
0: Object { Id: 1, Name: "Store", Description: "store description", … }
1: Object { Id: 59, Name: "Conference", Description: "conference text", … }
length: 2
<prototype>: Array []
<prototype>: Object { … }
length: 1
I would need to get the 'organizers' by Id (59 in this example). How would I go about adapting the code to go through the organizers.Id and to only get the organizer data based on a specific Id? I guess its iterate over the res.data.body.organizers to see if organizers.Id === const idVal?
Please note that the length of the main object is always 1, while 'organizers' can be many.