es-toolkit/docs/reference/array/uniqBy.md
novo 404d4a51a8
docs(uniqBy): fix docs for uniqBy (#231)
* docs: fix uniqBy doc example

* test: add test case

---------

Co-authored-by: Sojin Park <raon0211@toss.im>
2024-07-18 21:12:44 +09:00

648 B

uniqBy

Returns a new array containing only the unique elements from the original array, based on the values returned by the mapper function.

Signature

function uniqBy<T, U>(arr: T[], mapper: (item: T) => U): T[];

Parameters

  • arr (T[]): The array to process.
  • mapper ((item: T) => U): The function used to convert the array elements.

Returns

(T[]): A new array containing only the unique elements from the original array, based on the values returned by the mapper function.

Examples

uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);
// [1.2, 2.1, 3.2, 5.7, 7.19]