Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dedupe

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dedupe

easy deduplication of array values

  • 4.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
increased by9.95%
Maintainers
1
Weekly downloads
 
Created
Source

dedupe

removes duplicates from your array.

Installation

npm install dedupe

Usage

primitive types

import dedupe from 'dedupe'

const a = [1, 2, 2, 3]
const b = dedupe(a)
console.log(b)

//result: [1, 2, 3]

complex types

Here the string representation of the object is used for comparism. Internal JSON.stringify is used for serialization. That means that {} is considered equal to {}.

import dedupe from 'dedupe'

const aa = [{a: 2}, {a: 1}, {a: 1}, {a: 1}]
const bb = dedupe(aa)
console.log(bb)

//result: [{a: 2}, {a: 1}]

complex types types with custom hasher

You can use a custom hasher to overwrite the default behaviour.

import dedupe from 'dedupe'

const aaa = [{a: 2, b: 1}, {a: 1, b: 2}, {a: 1, b: 3}, {a: 1, b: 4}]
const bbb = dedupe(aaa, value => value.a)
console.log(bbb)

//result: [{a: 2, b: 1}, {a: 1,b: 2}]

Keywords

FAQs

Package last updated on 15 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc