uniqBy
uniqBy<
T,U>(iterable,keyOf,comparisonStrategy?):IterableIterator<T>
Defined in: set/uniq-by.ts:30
Yields the first item seen for each distinct keyOf(item), in
first-occurrence order.
Time complexity: O(n) under the default "sameValueZero".
Type Parameters
Section titled “Type Parameters”T
U
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The input iterable.
Callable<[T], U>
A function that takes an item and returns a key.
comparisonStrategy?
Section titled “comparisonStrategy?”EqualityComparisonStrategy<U, U> = "sameValueZero"
The equality comparison strategy for keys.
Returns
Section titled “Returns”IterableIterator<T>
An iterator over the first item seen for each distinct key.
Example
Section titled “Example” const array = [ { id: 1, name: "Alice" }, { id: 2, name: "Bob" }, { id: 1, name: "Alice" }, ]; [...uniqBy(array, (item) => item.id)]; // [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }] ```;