let arr1 = ['zhangsan','zhangsan','lisi','wangwu'];
let arr2 = new Set(arr1); //{"zhangsan", "lisi", "wangwu"}
arr1 = Array.from(arr2); //["zhangsan", "lisi", "wangwu"]
数据集合: set:
1、特点:
① 类似于数组,但没有重复的元素(唯一的);
② 开发中用于去除重复数据;
③ key和value都是相等的;
2、属性:
let set = new Set(['zhangsan','zhangsan','lisi','wangwu']);
console.log(set.size); // 3
3、方法:
① add方法:
vlet set = new Set(["zhangsan","lisi"]);
console.log(set); // {"zhangsan", "lisi"}
set.add("wangwu");
console.log(set); // {"zhangsan", "lisi", "wangwu"}
②delete方法:
let set = new Set(["zhangsan","lisi"]);
//直接将删除的值传进去即可
set.delete("lisi");
console.log(set); //{"zhangsan"}
③has方法:
let set = new Set(["zhangsan","lisi"]);
console.log(set.has("lisi")); //true
④clear方法:
let set = new Set(["zhangsan","lisi"]);
set.clear(); // 此时set为空了