去重:包括数组,字符串去重
// es6 set方法
let arr = [1, 4, 5, 1, 4, 3, 1, 7]
let arr1 = [2, 7, 9]
let arr2 = [8, 0];
let str = 'abcdefgacd';
//去重
console.log([...new Set(arr)]);//数组去重简写
//[1, 2, 3, 4, 5, 7, 8, 9, 0]
console.log(Array.from(new Set(arr)));//Array.from()将对象或其他转换为字符串
//[1, 2, 3, 4, 5, 7, 8, 9, 0]
console.log([...new Set(str)]);//字符串去重
//["a", "b", "c", "d", "e", "f", "g"]
console.log([...new Set(str)].join());//拼接字符串,将数组转换为字符串,join中不填写内容默认以逗号拼接
//a,b,c,d,e,f,g
console.log([...new Set(str)].join(''));
//abcdefg