Here I have an immutable list.I need to update isReq object to false for all the objects except the one having the id 2.
[
{
'id': 1,
'name': 'Ram',
'Details': {
'isReq': true
}
},
{
'id': 2,
'name': 'dev',
'Details': {
'isReq': true
}
},
{
'id': 3,
'name': 'joe',
'Details': {
'isReq': true
}
}
]
Use
mapand add an if-else branch:Here we use the object spread operator to update the item, but you could also use
Object.assignor something different entirely.