Returns a new array containing only the unique elements from the original array, based on the values returned by the mapper function. Based on https://es-toolkit.slash.page/reference/array/uniqBy.html
If there are multiple elements generating the same mapping, the first element among them is used as the value.
The type of elements in the array.
The type of mapped elements.
The array to process.
The function used to convert the array elements.
A new array containing only the unique elements from the original array, based on the values returned by the mapper function.
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]const array = [ { category: 'fruit', name: 'apple' }, { category: 'fruit', name: 'banana' }, { category: 'vegetable', name: 'carrot' },];uniqBy(array, item => item.category).length// 2 Copy
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]const array = [ { category: 'fruit', name: 'apple' }, { category: 'fruit', name: 'banana' }, { category: 'vegetable', name: 'carrot' },];uniqBy(array, item => item.category).length// 2
Returns a new array containing only the unique elements from the original array, based on the values returned by the mapper function. Based on https://es-toolkit.slash.page/reference/array/uniqBy.html
If there are multiple elements generating the same mapping, the first element among them is used as the value.