Mastering Immutable.js
上QQ阅读APP看书,第一时间看更新

Removing values from maps

Maps have a remove() method that works the same way as the list version. The only difference is that it takes a key as the argument instead of an index:

const myMap = Map.of(
'one', 1,
'two', 2,
'three', 3
);
const myChangedMap = myMap.remove('one');

console.log('myMap', myMap.toJS());
// -> myMap { one: 1, two: 2, three: 3 }
console.log('myChangedMap', myChangedMap.toJS());
// -> myChangedMap { three: 3, two: 2 }

By calling remove('one') on myMap, you get myChangedMap, a new map without the removed key.