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

187
Views
javascript - promise handling between for-loop and map()

using for-loop

    let arr=[]
    for (let mkt of markets) {
      const resA = await someAsyncFuncA(context, mkt[0].serumMarket);
      const resB = await someAsyncFuncB(resA);
      console.log(resB) 
      arr.push(resB)
    }
    console.log(arr) // it will log after the for-loop complete 

But when I am using map().

    let arr = [];
     markets.map(async (mkt) => {
      const resA = await someAsyncFuncA(context, mkt[0].serumMarket);
      const resB = await someAsyncFuncB(resA);
      console.log(resB) // it will log after console.log(arr) below
      arr.push(resB)
    });
    console.log(arr) // it will log first: []

I want to understand more for these 2 kinds of loop, such as the performance.
It seems map() always executes faster than for-loop, should I always use map()?
When should I use for-loop?

about 4 years ago · Juan Pablo Isaza
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!