uniqBy
arrayCreates a duplicate-free version of an array using a comparator function to determine uniqueness.
Signature
uniqBy<T, U>(array: T[], iteratee: (value: T) => U): T[]Parameters
| Name | Type | Description |
|---|---|---|
array | T[] | The array to inspect |
iteratee | (value: T) => U | The iteratee invoked per element |
Returns
T[] - Returns the new duplicate free array
Examples
With Math.floor
import { uniqBy } from 'dashlite'
const result = uniqBy([2.1, 1.2, 2.3], Math.floor)
console.log(result)Output:
[2.1, 1.2]With Objects
import { uniqBy } from 'dashlite'
const result = uniqBy([{ x: 1 }, { x: 2 }, { x: 1 }], (o) => o.x)
console.log(result)Output:
[{ x: 1 }, { x: 2 }]Available since version 1.0.0