3👍
As soon as you’ve read up on async/await
, you’ll still wanna run your requests in parallel to save time, rather than sequentially. Promise.all
helps here:
async function fetchData () {
const resultsInOrder = await Promise.all(
// pass an array of Promises
array.map(element =>
fetch(/* some arguments based on the element's data */)
.then(res => res.json())
)
)
// do something with results
}
Source:stackexchange.com