1.0.1 • Published 6 years ago

remove-one v1.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

remove-one

Build Status dependencies Status JavaScript Style Guide

Fast remove a single element from an array

Using Array.filter you iterate over the whole array to remove just a single item. This module uses Array.findIndex to find the item you want to remove and Array.splice to remove it. Returns a new array.

Install

npm install remove-one

Usage

const removeOne = require('remove-one')
const array = [0, 1, 2, 3]
const result = removeOne(array, (n) => n === 1)

console.log(array) // [0, 1, 2, 3]
console.log(result) // [0, 2, 3]