toggle-in-array
Add or remove item from array
Install
npm install --save toggle-in-array
Usage
var toggleInArray = ; //=> [1, 3] //=> [1, 2, 3, 4] //=> [{v: 1}, {v: 3}]
API
toggleInArray(array, value, [predicate])
Returns an Array
with value
if array
is not includes this value
Returns an Array
without value
if array
is includes this value
array
Required
Type: Array
Array with values needs to toggle
value
Required
Type: *
Value to toggle in array
predicate
Type: Function
Default: (a, b) => a === b
Strict equality comparison
Function that compare each array
item to equal value
License
MIT © Vladimir Rodkin