I am using PokeApi and I want to save data that is inside of another API using its ID´s, but it could be more than 1 so I want to save it in a array. By now I am using two methods, one get the api and verify if the information is there.
const evolutionChain = async (URLEC)=> {
var chain=[]
const getURL= await fetch(URLEC);
const res1 = await getURL.json();
chain.push(getPoke(res1.chain.species.url));
if(res1.chain.evolves_to.length!==0){
chain.push(getPoke(res1.chain.evolves_to[0].species.url));
}
if(res1.chain.evolves_to[0].evolves_to[0].length!==0){
chain.push(getPoke(res1.chain.evolves_to[0].evolves_to[0].species.url));
}
return chain;
}
URLEC is "https://pokeapi.co/api/v2/evolution-chain/1/".
And the other function get the another URL and get the info
const getPoke= async (url)=>{
const getURL= await fetch(url);
const res1 = await getURL.json();
const res2 = await fetch( `https://pokeapi.co/api/v2/pokemon/${res1.id}`);
const res3 = await res2.json();
const poke= {
name: res3.name
}
return poke;
}
At the end it returns me the entire promise that have an array of promises like this: