Another type of persistent change that you'll want to make is to remove values from collections. Both lists and maps have methods to remove values from them, which results in new collections.
If you know the index of the list value that you want to remove, you can pass the index to the remove()
method to create a new list without the removed value, as follows:
const myList = List.of(1, 2, 3); const myChangedList = myList.remove(0); console.log('myList', myList.toJS()); // -> myList [ 1, 2, 3 ] console.log('myChangedList', myChangedList.toJS()); // -> myChangedList [ 2, 3 ]
You can see here that myChangedList
results from calling remove(0)
. It's a new list, without the first value.