You want to execute an async function inside a map() call, to perform an operation on every element of the array, and get the results back.

How can you do so?

This is the correct syntax:

const list = [1, 2, 3, 4, 5] // 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( => anAsyncFunction(item)))

getData().then(data => {

The main thing to notice is the use of Promise.all(), which resolves when all its promises are resolved. returns a list of promises, so in result we’ll get the value when everything we ran is resolved.

Remember, we must wrap any code that calls await in an async function.

See the promises article for more on promises, and the async/await guide.

Download my free JavaScript Beginner's Handbook and check out my JavaScript Course!

More js tutorials: