removeduplicates

1.1.0 • Public • Published

removeDuplicates

Function that removes duplicates from an array.

Install

npm install removeduplicates

Usage

var removeDuplicates = require('removeDuplicates');

Remove duplicate items

var tempArray = ["tom", "jack", "jake", "tom"];
 
var uniqueArray = removeDuplicates(tempArray);

uniqueArray will now equal the following

["tom", "jack", "jake"];

Remove duplicate objects

Passing in your array of objects as the first parameter, and the key you're checking against as the second parameter. The function will remove any duplicate values based on this key.

var tempArray = [
    {
        id: 1234,
        selected: true,
        otherVal: 'abc'
    },
    {
        id: 5678,
        selected: false,
        otherVal: 'abc'
    },
    {
        id: 1234,
        selected: true,
        otherVal: 'def'
    }
];
 
var uniqueArray = removeDuplicates(tempArray, 'id');

uniqueArray will now equal the following

[
    {
        id: 1234,
        selected: true,
        otherVal: 'abc'
    },
    {
        id: 5678,
        selected: false,
        otherVal: 'abc'
    }
];

Readme

Keywords

none

Package Sidebar

Install

npm i removeduplicates

Weekly Downloads

17

Version

1.1.0

License

ISC

Last publish

Collaborators

  • tjcafferkey