I have a huge list of array of object, and I have an API endpoint that has queue limit, I got error writing this
arr.forEach(async o => {
const result = await callAPI(o.id)
//do something
})
but it is fine when I convert forEach to native for loop
for (let i = 0; i < arr.length; i++) {
const o = arr[i];
const result = await callAPI(o.id)
//do something
};
Why? as I know I can do something similar with map where it is async, like
const transformedResult = Promise.all(arr.map(o => ({...o, newProp: await callApi(o.id) }) )
await transformedResult //will wait till callApi is resolved