Created
August 6, 2021 16:10
-
-
Save landonconover/61cc1d4af5bc225cf0abf2f1a54ee177 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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