0

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: Results

yousoumar
  • 7,434
  • 4
  • 9
  • 33
  • 1
    Is this different to your [earlier question](https://stackoverflow.com/questions/72350977/how-i-can-call-a-fetch-inside-a-promise)? – jarmod May 23 '22 at 18:23
  • 1
    You already know how to use `Promise.all` (as demonstrated by your previous questions). Why don't you use it here? – Bergi May 23 '22 at 19:00

0 Answers0