duplicate-js

Simple way to filter your duplicates

Usage no npm install needed!

<script type="module">
  import duplicateJs from 'https://cdn.skypack.dev/duplicate-js';
</script>

README

duplicatejs


duplicatejs can help you find what array values are new and not exists in another array.

Installation

node

Install using npm

npm install duplicate-js
const duplicate = require("duplicate-js");

duplicate(array1, array2, options)

Examples

Notice that the filtered array is the first one (array1)

Code

const duplicate = require("duplicate-js");

let array1 = ['a', 'b', 'c'];
let array2 = ['c', 'd', 'e'];

let filtered = duplicate(array1, array2)

Result

[ 'a', 'b' ]

Code

const duplicate = require("duplicate-js");

let array1 = [{id: 123}, {id: 456}];
let array2 = [{id: 123}, {id: 789}];

let filtered = duplicate(array1, array2, {
    property: 'id'
})

Result

[ { id: 456 } ]