new Set() 数组去重

new Set(),用来去重数组。

let arr = [1, 2, 2, 3];
let set = new Set(arr);
let newArr = Array.from(set);
console.log(newArr); // [1, 2, 3]

Set类似于数组,区别在于它所有的成员都是唯一的,不能有重复的值

猜你喜欢

转载自www.cnblogs.com/crdanding/p/12302214.html