Es6 过滤唯一值 的简单方法

Set对象类型是在ES6中引入的,配合展开操作...一起,我们可以使用它来创建一个新数组,该数组只有唯一的值。

const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // Result: [1, 2, 3, 5]
posted @ 2019-08-05 15:12  IT攻略  阅读(427)  评论(0编辑  收藏  举报