map映射

采集于:https://blog.csdn.net/luanpeng825485697/article/details/78056312

 

映射map:

var map = new Map(); //映射,不重复的键,以键值对的形式存在

map.set("name","mapluanpeng"); //添加设置映射

if(map.has("name")) //判断映射是否存在

printf(map.get("name")); //读取映射

map.delete("name"); //删除映射

 

 

集合Set

 

var set1 = new Set(["name1","name2","name3"]); //集合。不重复的元素集合,不存在键值对

set1.add("name"); //添加集合 if(set1.has("name")){ //检测集合是否存在指定元素

set1.delete("name"); //删除集合元素 set1.clear(); //清空集合元素

console.log(set1.size); //集合大小 }

set1 = new Set(["name1","name2","name3"]);

var set2 = new Set(["name1","name3","name5"]); //并集

let union = new Set([...set1, ...set2]); //交集

let intersect = new Set([...set1].filter( x => set2.has(x))); //差集

let difference = new Set([...set1].filter(x => !set2.has(x)));

posted @ 2018-05-14 14:39  麻楠子  阅读(296)  评论(0编辑  收藏  举报