September 2017
Intermediate to advanced
216 pages
6h 8m
English
The set() method for maps is used to add and to change collection values. If the key that's being set doesn't exist, then the key-value pair is set for the first time. If the key does exist, then the previous value of that key is replaced with the new value, as follows:
const myMap = Map.of('one', 1);const myChangedMap = myMap.set('one', 'one');console.log('myMap', myMap.toJS());// -> myMap { one: 1 }console.log('myChangedMap', myChangedMap.toJS());// -> myChangedMap { one: 'one' }
Calling set() produces a new map, because all Immutable.js mutations are persistent changes.
Read now
Unlock full access