Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
Array with map returning pending promisse

im trying to make an array empty and use map to change the array fatch but when a do console.log on array it return's a pending promise

    const arrayPokemons = Array(5)
      .fill()
      .map((item, index) =>
        fetch(`https://pokeapi.co/api/v2/pokemon/${index + 1}`)
          .then((res) => res.json())
          .then((data) => data.name)
      );
    
    console.log(arrayPokemons);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You just need to resolve the promises. The code you provided maps each element of the array to a Promise, so you now have five Promises. To resolve them all -- wait for all of them to resolve -- and access the results, you can use Promise.all.

The revised snippet below does that, and works as you intended.

const promises = Array(5)
  .fill()
  .map((item, index) =>
    fetch(`https://pokeapi.co/api/v2/pokemon/${index + 1}`)
      .then((res) => res.json())
      .then((data) => data.name)
  );
    
Promise.all(promises).then((arrayPokemons) => {
  console.log(arrayPokemons)
})

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda