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

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.

主站蜘蛛池模板: 旬邑县| 松阳县| 永和县| 句容市| 定南县| 宣汉县| 许昌县| 界首市| 澳门| 上思县| 衡东县| 阿拉善右旗| 霍林郭勒市| 个旧市| 连江县| 于田县| 巫山县| 翼城县| 绍兴县| 剑河县| 抚顺县| 花垣县| 明水县| 荆州市| 清涧县| 平山县| 宁武县| 日照市| 贵州省| 峨山| 通化县| 启东市| 义乌市| 绥棱县| 宁晋县| 新源县| 旬邑县| 峨眉山市| 陈巴尔虎旗| 英超| 天水市|