ES6-map数据结构,增加、删除、查找 方法(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

 

posted @ 2019-06-23 01:51  Ananiah  阅读(2929)  评论(0编辑  收藏  举报