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

104
Views
How to get actual data insead array of promise in map async await

i have leads of array, i need to catch the activityFor from array and find the data from mongo database by using mongoose and replace that data, when i am doing with map function i am getting array of promise

const newData = leads.map(async (data) => {
      _activityFor = await User.find({ _id: { $in: data.activityFor } }).select(
        " name employeeId"
      );
      data.activityFor = _activityFor;
      console.log("data", data);
      return data;
    });

console.log("newData", newData);

output:

newData [
  Promise { <pending> },
  Promise { <pending> },
  Promise { <pending> },
  Promise { <pending> }
]

please let me know how can i get actual array of data instead of promise array

And if I am using like this also get the same result

const newData = leads.map(function (obj) {
      return User.find({ _id: { $in: obj.activityFor } })
        .select(" name employeeId")
        .exec()
        .then((dd) => {
          obj.activityFor = dd;
          return obj;
        });
    });

    console.log("newData", newData);
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!