I have an array made by Immutable.js:
var arr = Immutable.List.of(
{
id: 'id01',
enable: true
},
{
id: 'id02',
enable: true
},
{
id: 'id03',
enable: true
},
{
id: 'id04',
enable: true
}
);
How can I find the object with id: id03
? I want to update its enable
value and get an new array
First you need to findIndex, and then update your List.
const index = arr.findIndex(i => i.id === 'id03')
const newArr = arr.update(index, item => Object.assign({}, item, { enable: false }))
OR
const newArr = arr.update(
arr.findIndex(i => i.id === 'id03'),
item => Object.assign({}, item, { enable: false })
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With