Javascript ES6 数组去重

阅读(2763)

ES6 引入了新的数据结构 Set,其成员是唯一的,没有重复的。利用这个特性简化数组去重。

Array.from(new Set([1, 2, 2, 3, 3, 1, 2, 3, 4]));

或者使用扩展运算符

[...(new Set([1, 2, 2, 3, 3, 1, 2, 3, 4]))]

Refer:
http://es6.ruanyifeng.com/#docs/set-map#Set

Tags: es6