版权声明:== https://github.com/fyonecon == https://blog.csdn.net/weixin_41827162/article/details/82781796
-
Map与数组字典有相似性,如下:
let array = [
{
type:'text',
content:'abcdefg',
},
{
type:'number',
content:'12345678',
},
];
操作Map,如下:
let map = new Map([
["one", 1],
["two", 2],
]);
map.set("one", 11); map.set("two2", 2); map.set("three", 3); // 添加或者更新Map键值对
console.log(map);
console.log(typeof map);
console.log(map.size);
console.log(map.get("one"));
console.log(map.has("one"));
for (let key of map.keys()){
console.log(key);
}
for (let value of map.values()){
console.log(value);
}
for (let [key, value] of map){
console.log(key + "-" + value);
}
-