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

201
Views
How to update an object using for-of loop in node.js

Obj.users is an array of users in the form of objects, I want to add an additional property i:e "priority" to the each user object. Since I don't have the index of each user's object so I'm trying to update it with the loop variable but when I console.log it, It's not getting updated.

Obj.users and interests are both arrays.

router.get("/", auth, async function (req, res) {
  const { email, interests } = req.user;
  const obj = {};
  var counter = 0;
  obj.users = await User.find(req.user._id);
  for (var i of obj.users) {
    for (var j of interests) {
      if (i.interests.includes(j)) {
        counter = counter + 1;
      }
    }
    i.priority = counter;
    counter = 0;
  }
  console.log(obj.users);
});
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!