Reputation: 270
Can anyone tell me what how to update 'value' by id in this structue in ImmutableJS?
map = {
list: [
{
id: 1,
value: 'update'
}
]
}
Upvotes: 0
Views: 86
Reputation: 131
You can use the code below. However, it is not the best solution, because that will search all items in the list. If you can change your structure instead of List
you can use OrderedMap
.
var newData = map.set("list", map.get("list").map(data => data.get("id") === 1 ? data.set("value", "updatedValue") : data));
Upvotes: 0