uniqBy
@guoba-ai/utils / array / uniqBy
Function: uniqBy()
function uniqBy<T>(array, fn): T[];Defined in: array.ts:54
Remove duplicate elements from an array by a derived key.
Parameters
array
T[]
The input array
fn
(item) => unknown
Function that returns the key used for uniqueness
Returns
T[]
A new array with the first item for each key, preserving order
Example
uniqBy([{ id: 1 }, { id: 2 }, { id: 1 }], item => item.id)
// [{ id: 1 }, { id: 2 }]