Skip to content

Instantly share code, notes, and snippets.

@jjmartucci
Created May 7, 2020 16:42
Show Gist options
  • Save jjmartucci/406ac4d492ee47363950bfcca9532cf9 to your computer and use it in GitHub Desktop.
Save jjmartucci/406ac4d492ee47363950bfcca9532cf9 to your computer and use it in GitHub Desktop.
Using Async / Await with Array.map()
let characterResponse = await fetch(‘<http://swapi.co/api/people/2/>’)
let characterResponseJson = await characterResponse.json()
let films = await Promise.all(
characterResponseJson.films.map(async filmUrl => {
let filmResponse = await fetch(filmUrl)
return filmResponse.json()
})
)
console.log(films)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment