uniqBy es-toolkit
Returns a new array with duplicate elements removed based on values returned by the transformation function.
Usage
uniqBy(arr, mapper)
Use uniqBy when you want to transform elements by a specific criterion and determine duplicates. It only keeps the first occurrence among elements for which the transformation function returns the same value.
You can also base it on a combination of specific fields in complex objects.
Parameters
The array from which to remove duplicates.
A function that transforms each element into a value for comparison. It receives the element, its index, and the array.
Returns
A new array with duplicates removed based on the transformation function's results. Preserves the order in which they first appear in the original array.
Examples
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.