I am encountering an issue with assigning a new property to each object in an array, which is obtained through an async function within a map method. Here is the code snippet that I am using:
asyncFunction.then(array => {
var promises = array.map(obj => {
return otherAsyncFunction(obj._id).then(prop => {
obj.url = prop;
return obj
})
})
Promise.all(promises).then(function (results) {
console.log(results)
})
res.send(user.friends)
})
Despite my efforts, when I call console.log(results)
, it displays the same array as before.
In order to troubleshoot, I tried logging the 'obj' just before the return obj
statement and realized that it also shows the old 'obj' value.