Package Exports
- unique-array-by
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (unique-array-by) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
unique-array-by
Filters an array by testing uniqueness with a callback, an index, or a key.
Optionally lets you set a numeric limit on total unique values returned.
If you merely need to remove duplicate values from an array, use the simpler deduplicate module instead.
Installation
npm install unique-array-by --saveThe module exports a single function.
Usage Example
Let’s say you have an array of person objects and you only want one person with any given name.
const uniqueArrayBy = require('unique-array-by')
const people = [
{name: 'John'},
{name: 'John'},
{name: 'Stephen'},
]
uniqueArrayBy(people, 'name') // [{name: 'John'}, {name: 'Stephen'}]Or you can use a callback that retrieves the significant value:
uniqueArrayBy(people, person => person.name) // [{name: 'John'}, {name: 'Stephen'}]You can also use the limit argument to cap the number of total unique values returned:
uniqueArrayBy(people, 'name', {limit: 1}) // [{name: 'John'}]