I am trying to fetch a data inside for loop and it's using async await and want to populate that data in the existing object array but it doesn't work.
Here is my code:
for (let i = 0; i < listing.length; i++) {
var listingDetails = null;
(async () => {
const list = await sdk.listing.query({ listing_id: listing[i].id })
listingDetails = list.data && list.data.data // I am expecting this to replace the default value of listingDetails variable
})()
listing[i].details = listingDetails
console.log(listingDetails) // But when it comes here, the listingDetails is still null
}
The last console.log(), I was expecting the data to be there but it wasn't there. Due to this, I am unable to re-populate the details.