Socket
Socket
Sign inDemoInstall

addtoset

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    addtoset

Utility array function to add value to array if doesn't exist


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Install size
3.34 kB
Created
Weekly downloads
 

Readme

Source

© ,Kailash Yogeshwar, Licensed under MIT-License

addToSet

A library to add an element to array set if doesn't already exist else return the source array.

Install

npm install addtoset -S

Features

Adds element to array if it doesn't already exist in array and return the new array version with modified value if any.

const addToSet = require('addtoset');
const set      = new addToSet();

let arr = [1,2,3,4,5];

arr = set.push(arr, 6); // [1,2,3,4,5,6]
arr = set.push(arr, 1); // [1,2,3,4,5]

// Error if parameter is not array
let str = "msg";

set.push(str,1); // Error: Source must be array 

Thank you. Happy Coding

Keywords

FAQs

Last updated on 04 Apr 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc