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

254
Views
Using Await While Looping a Map Object

How can you iterate over each value in a Map, in manner where await will be honored in the body of that loop?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I ultimately used map.values() within a for await loop.

Here's a contrived example that showcases await working within a loop:

async function delay(ms)
{
  console.log(`Waiting ${ms} milliseconds . . .`);
  return new Promise((resolve)=>{ setTimeout(resolve, ms); });
}

async function main()
{
  let map = new Map([[1,"A"],[2,"B"],[3,"C"]]);

  for await (const value of map.values())
  {
          await delay(2000);
          console.log(value);
  }
}
main();

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!