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

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.

主站蜘蛛池模板: 林口县| 蒙城县| 昌黎县| 方正县| 阜平县| 盐津县| 景德镇市| 余江县| 墨玉县| 江津市| 闸北区| 萝北县| 神农架林区| 连云港市| 伊宁市| 唐山市| 芜湖市| 东源县| 蒙自县| 外汇| 宁海县| 九江县| 延津县| 湛江市| 巴塘县| 五家渠市| 山阳县| 娱乐| 玉田县| 双桥区| 宣城市| 平山县| 和平区| 大同县| 武山县| 正宁县| 江北区| 镇赉县| 桑日县| 孟津县| 南和县|