ES6 利用 Set 数组去重法

例子:

  const set = new Set();

  [2, 3, 5, 4, 5, 2, 2].forEach(x => set.add(x) );

  const arr = [...set];

  console.log(arr);  // [ 2, 3, 5, 4 ]

稍做一下解释:

  因为,ES6 提供了新的数据结构 Set。它类似于数组,但是成员的值都是唯一的,没有重复的值。

  所以,可以做出这样的方法;

原文地址:https://www.cnblogs.com/cnblogs-jcy/p/8508318.html