ES6map数据结构,增加、删除、查找 方法(set get has delete clear ) 属性:size

 

 
map数据结构:
本质上是键值对的集合,类似集合;
可以遍历,方法很多,可以跟各种数据格式转换。
复制代码
let json = {
    name:'ananiah',
    age:'18'
}
//效率低 需要遍历json
console.log(json.name);
复制代码
声明map
复制代码
//声明map
var map = new Map();
map.set(json,'web');
console.log(map) //Map(1) {{…} => "web"}
map.set('wulala',json);
console.log(map) //Map(2) {{…} => "web", "wulala" => {…}}  //key: "wulala" value: {name: "ananiah", age: "18"}
复制代码
map中增加、删除、查找 方法(set get has delete clear ) 属性:size
复制代码
//map中增加、删除、查找 方法(set get has delete clear ) 属性:size
 //get 取值
 console.log(map.get(json))
 //删除 delete
 map.delete(json)
 console.log(map)
//  删除全部
// map.clear();
//长度
console.log(map.size)
//查找 true false
console.log(map.has('ananiah')) //false
复制代码
原文地址:https://www.cnblogs.com/onesea/p/15544195.html