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);
});