Skip to content

Instantly share code, notes, and snippets.

@landonconover
Created August 6, 2021 16:10
Show Gist options
  • Save landonconover/61cc1d4af5bc225cf0abf2f1a54ee177 to your computer and use it in GitHub Desktop.
Save landonconover/61cc1d4af5bc225cf0abf2f1a54ee177 to your computer and use it in GitHub Desktop.
//a function to get the full pokemon from the pokemon api.
async function getAllPokemon() {
//get the list of pokemon with the urls.
let response = await fetch('https://pokeapi.co/api/v2/pokemon/');
let pokemon = await response.json()
//make a fetch call for each pokemon
let pokePromises = pokemon.results.map(async(poke) => {
let response = await fetch(poke.url);
let pokeJson = await response.json()
return pokeJson;
})
//when all the pokemon promises reslove, return the pokemon array
return Promise.all(pokePromises)
}
getAllPokemon().then(pokemon => {
console.log('pokemon',pokemon)
//do stuff with the pokemon here. 😁
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment