Is there a way to rearrange items within an unchangeable list that is part of a Map
? Here's an example:
const Map = Immutable.fromJS({
name:'lolo',
ids:[3,4,5]
});
I have attempted to use the splice
method for swapping, as well as the insert()
method provided by Immutable.
For instance, if I want to swap from [3, 4, 5]
to [3, 5, 4]
, my attempt looks like this:
list.set('ids', list.get('ids').splice(2, 0, list.get('ids').splice(1, 1)[0])
What is the most effective way to rearrange elements inside Immutable data structures using Immutable.js? Let me know, please.