I am using map() over a long array and using fetch for each value. It will take many seconds to complete. I would like to know when the final push is complete and use the data in the array.
I tried Promise, Promise.all, Async/Await, but may have missed something obvious. I created this sample code to more simply illustrate the problem.
const arr = new Array(100).fill("todos")
const arrPush = []
const result = arr.map(data => {
fetch(`https://jsonplaceholder.typicode.com/${data}`)
.then(res => res.json())
.then(res => arrPush.push(res))
})
Promise.all(result).then(() => console.log(arrPush))
When the final value is added to array, do something. In this case console.log the complete array.