Skip to content

Instantly share code, notes, and snippets.

@YMA-MDL
Created November 23, 2019 08:51
Show Gist options
  • Save YMA-MDL/6b92392819fb717beaec93b0f7491661 to your computer and use it in GitHub Desktop.
Save YMA-MDL/6b92392819fb717beaec93b0f7491661 to your computer and use it in GitHub Desktop.
Wait for .map to execute #javascript #vanillajs
const list = [1, 2, 3, 4, 5] //...an array filled with values
const functionWithPromise = item => { //a function that returns a promise
return Promise.resolve('ok')
}
const anAsyncFunction = async item => {
return functionWithPromise(item)
}
const getData = async () => {
return Promise.all(list.map(item => anAsyncFunction(item)))
}
getData().then(data => {
console.log(data)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment