Function: uniqBy()
ts
function uniqBy<T, K>(array, iteratee): T[];Removes duplicate items from an array using a derived key. 按派生键对数组去重。
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of array items / 数组元素类型 |
K | The derived key type / 派生键类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | The source array / 源数组 |
iteratee | UniqByIteratee<T, K> | The property name or function used to derive the uniqueness key / 用于生成唯一键的属性名或函数 |
Returns
T[]
A new array containing the first item for each unique key / 每个唯一键保留首个元素的新数组
Example
ts
uniqBy([{ id: 1 }, { id: 1 }, { id: 2 }], 'id')
// => [{ id: 1 }, { id: 2 }]Since
1.2.0