JSPM

unique-array-by

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q30800F
  • License MIT

Filters an array by testing uniqueness with a callback, an index, or a key.

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 --save

The 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'}]