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

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.

主站蜘蛛池模板: 双柏县| 平定县| 蓬莱市| 荥阳市| 中西区| 文成县| 泸水县| 辽宁省| 荆州市| 黄大仙区| 烟台市| 彝良县| 南岸区| 綦江县| 扶绥县| 汽车| 信丰县| 长泰县| 天等县| 临沂市| 韶山市| 邹平县| 南通市| 四子王旗| 准格尔旗| 沙河市| 永寿县| 布尔津县| 安塞县| 大新县| 太谷县| 天峻县| 许昌市| 灵寿县| 周至县| 商水县| 遂川县| 杂多县| 东源县| 米泉市| 西林县|