// 1、创建Set
// var set = new Set()
// console.log(set);
// console.log(typeof set);
// var set = new Set(1)
// var set = new Set(false)
//boolean false is not iterable
var set = new Set([10, 20, 30, 40])
console.log(set);
set.add(50)
console.log(set);
set.add(50)
set.add(60)
console.log(set);
console.log(set.size);
console.log(set.delete(10));
console.log(set);
console.log(set.delete(10));
console.log(set);
// set.clear()
console.log(set);
console.log(set.has(10));
console.log(set.has(20));
console.log(set.entries());
for (let [key, value] of set.entries()) {
console.log(key);
console.log(value);
}
console.log(set.keys());
console.log(set.values());
set.forEach((item, index) => {
console.log(item);
console.log(index);
})
var set1 = new WeakSet([{ age: 1 }, set, [1, 2, 3]])
console.log([1, 2] == [1, 2]);
console.log(set1);
set1.add([1, 2])
var arr3 = [10, 20]
set1.add(arr3)
console.log(set1);
// set1.delete(arr3)
console.log(set1);
// set1.delete(set1[0])
// console.log(set1);
console.log(set1.has(arr3));
数组去重:(重点)
// var arr = [1, 2, 3, 4, 1, 2]
// var set1 = new Set(arr)
// console.log(set1);
// console.log([...set1]);
// console.log(Array.from(set1));
// console.log([...new Set(arr)]);