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

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.

主站蜘蛛池模板: 开原市| 平遥县| 中宁县| 海原县| 西贡区| 东丰县| 阳信县| 三河市| 鄂州市| 师宗县| 南投县| 灵寿县| 红安县| 连云港市| 永靖县| 宁陵县| 威信县| 孟村| 临西县| 黔江区| 平顺县| 舞阳县| 沂南县| 深泽县| 大余县| 浪卡子县| 双鸭山市| 浏阳市| 泸西县| 凤城市| 马鞍山市| 南江县| 嘉峪关市| 肥乡县| 平遥县| 巨鹿县| 阿克| 宿州市| 大埔县| 海宁市| 介休市|