Hello I have the following function
update: (id) => {
let updated = false
database.users = database.users.map((user) => {
if(user.id === id){
updated = true
user.active = true;
}
return user
})
return updated
}
As you can see the function iterates over an array in order to update the attribute user.active, and update the updated variable declared outside.
I debugged this and the function enter inside the if, and update the value, but always return updated = false.
How can I do to update that variable?
I am using node v14.16.1, with babel:
{
"presets": [
"@babel/preset-env"
]
}
UPDATED
- The database is a JSON object is not asynC
- The database can have more than one user with the same id
The questions about why updated don't is updated inside the arrow function.
Thanks.