标题 | 标签 |
---|---|
uniqueElements(数组去重) | array(数组) |
查找数组中的所有唯一值。
- 从给定的数组创建一个 Set 以丢弃重复的值。
- 使用扩展运算符 (...) 将其转换回数组。
const uniqueElements = arr => [...new Set(arr)];
调用方式:
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]
应用场景
标题 | 标签 |
---|---|
uniqueElements(数组去重) | array(数组) |
查找数组中的所有唯一值。
const uniqueElements = arr => [...new Set(arr)];
调用方式:
uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1, 2, 3, 4, 5]
应用场景