September 2017
Intermediate to advanced
216 pages
6h 8m
English
You can follow the same approach with maps when you need to add more than one value at the same time. Instead of chaining together the push() calls as you would with a list, you call set():
const myMap = Map.of( 'one', 1, 'two', 2, 'three', 3);const myChangedMap = myMap .set('four', 4) .set('five', 5) .set('six', 6);console.log('myMap', myMap.toJS());// -> myMap { one: 1, two: 2, three: 3 }console.log('myChangedMap', myChangedMap.toJS());// -> myChangedMap { one: 1, two: 2,// -> three: 3, four: 4,// -> five: 5, six: 6 }
The first two calls to set() create intermediary maps, while the last call to set() produces the final map that ends up in myChangedMap.
Read now
Unlock full access