数组去除重复成员的方法

数组去除重复成员的方法

1.去除数组重复成员的一种方法:

function dedupe(array) {
  return Array.from(new Set(array));
}

dedupe([1, 1, 2, 3]) // [1, 2, 3]

2.扩展运算符和 Set 结构相结合,就可以去除数组的重复成员:

let arr = [3, 5, 2, 2, 5, 5];
let unique = [...new Set(arr)];
// [3, 5, 2]