array-toggle

1.0.3 • Public • Published

arrayToggle

Return an Array with a value included/removed, with optional forcing.

I made this function because I found one of the most annoying situations I've run into with Arrays, is toggling values.. but also being able to force whether the value stays present or not.

Example:

import arrayToggle from "array-toggle";
 
const list = [1, 2, 3];
const toggled = arrayToggle(list, 2);
 
console.log(toggled);
[1, 3]

The third argument of arrayToggle allows forcing the value's state within the Array, in an event where its membership may be governed by some other value, such as a checkbox being checked or not.

Example:

import arrayToggle from "array-toggle";
 
const list = [1, 2, 3];
const toggled = arrayToggle(list, 2, true);
 
console.log(toggled);
[1, 2, 3]

Readme

Keywords

Package Sidebar

Install

npm i array-toggle

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

3.2 kB

Total Files

6

Last publish

Collaborators

  • gvanderest