Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!