Skip to content
For when you just need lodash uniqBy without all the baggage of lodash
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
index.js
package.json

README.md

uniq-by

For when you just need lodash uniqBy without all the baggage of lodash. It removes duplicate items from an array based on a key.

Installation

npm install uniq-by

Usage

It takes an array and a key and returns unique elements by that key.

const uniqBy = require('uniq-by')
const arr = [
  {
    id: 1,
    name: 'Alice'
  },
  {
    id: 2,
    name: 'Alice'
  },
  {
    id: 1,
    name: 'Bob'
  }
]

uniqBy(arr, 'id') // [{ id: 1, name: 'Alice'}, { id: 2, name: 'Alice'}]
uniqBy(arr, 'name') // [{ id: 1, name: 'Alice'}, { id: 1, name: 'Bob'}]
You can’t perform that action at this time.