Returns all unique values in an array.

Create a Set from the given array to discard duplicated values, then use the spread operator (...) to convert it back to an array.

代码片段

const uniqueElements = arr => [...new Set(arr)];

使用样例

uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]