Array 去重
小于 1 分钟
Array
去重
模块
类型
interface Array<T> {
uniqueBy(resolver?: (item: any) => any): Array<T>;
}
interface TypedArray {
uniqueBy(resolver?: (item: any) => any): TypedArray;;
}
入口点
core-js/proposals/array-unique
core-js(-pure)/full/array(/virtual)/unique-by
core-js/full/typed-array/unique-by
示例
示例:
[1, 2, 3, 2, 1].uniqueBy(); // [1, 2, 3]
[
{ id: 1, uid: 10000 },
{ id: 2, uid: 10000 },
{ id: 3, uid: 10001 },
].uniqueBy((it) => it.uid); // => [{ id: 1, uid: 10000 }, { id: 3, uid: 10001 }]