remove-array-item

1.1.1 • Public • Published

remove-array-item

Build Status Build Status David

A simple utility to (recursively) remove specified item(s) from an array.

Install

npm i remove-array-item --save

Usage

removeArrayItem(arr, item)

The module simply exports a function; the first argument is the current array, the next is the item that should be removed from all arrays/nested arrays.

It uses a "naive" indexOf implementation, and so does not do any deep equality checks on objects or the like.

Examples

import removeArrayItem from 'remove-array-item';
 
const arr = removeArrayItem(['red', 'green', ['red', 'blue']], 'red');
 
// arr will be ['green', ['blue']]

Aditionally, note that additional arguments can be passed (in sequence), and so multiple items can be removed in one statement, a la the following example:

const arr = removeArrayItem(['red', 'green', ['blue']], 'red', 'green');
 
// arr will be [['blue']]

Package Sidebar

Install

npm i remove-array-item

Weekly Downloads

0

Version

1.1.1

License

MIT

Last publish

Collaborators

  • dschau