官术网_书友最值得收藏!

Adding key-value pairs to maps

With maps, we use the set() method to add new values. Like the push() method used with lists, set() results in a new map:

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

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 }

You have to supply the new key for the map, which can be any type of value, not just strings, along with the value itself. This results in the new map being stored in myChangedMap, which has the key-value pair that you've just set.

主站蜘蛛池模板: 耒阳市| 苍南县| 邻水| 徐水县| 崇明县| 赣榆县| 融水| 宝兴县| 永定县| 义马市| 柞水县| 诸暨市| 玉山县| 德州市| 娱乐| 通山县| 尼勒克县| 正阳县| 克什克腾旗| 昌江| 扎鲁特旗| 桐柏县| 巴楚县| 万年县| 惠东县| 本溪市| 资阳市| 海淀区| 乐清市| 定远县| 丽江市| 交口县| 茌平县| 海阳市| 赣州市| 吴忠市| 本溪| 无锡市| 专栏| 淳化县| 桃园市|