uniq-by

1.0.1 • Public • Published

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i uniq-by

      Weekly Downloads

      4

      Version

      1.0.1

      License

      MIT

      Unpacked Size

      1.34 kB

      Total Files

      3

      Last publish

      Collaborators

      • mikemcbride