1.0.1 • Published 5 years ago

array.omit v1.0.1

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

array.omit

JavaScript library for omitting items from an array that works with both Node.js and web browsers.

Install

If you are using Node.js, you can get the library from npm.

npm install --save array.omit

If you are using a web browser, you can get the latest version of array.omit from the unpkg cdn.

<script src="https://unpkg.com/array.omit@1.0.1/index.js"></script>

Example

Basic Usage Example

var animals = ['cat', 'dog', 'cow', 'chicken'];

console.log(animals); // [ 'cat', 'dog', 'cow', 'chicken' ]

var updatedAnimals = animals.omit('cow');

console.log(updatedAnimals); // [ 'cat', 'dog', 'chicken' ]

Omit by Key Value

var animals = [{animal:'cat', age:1}, {animal:'cat', age:3}, {animal:'cat', age:6}];

console.log(animals); // [ { animal: 'cat', age: 1 }, { animal: 'cat', age: 3 }, { animal: 'cat', age: 6 } ]

var updatedAnimals = animals.omit({age:3});

console.log(updatedAnimals); // [ { animal: 'cat', age: 1 }, { animal: 'cat', age: 6 } ]

Omit by Function/Filter

var animals = [{animal:'cat', age:1}, {animal:'cat', age:3}, {animal:'cat', age:6}];

console.log(animals); // [ { animal: 'cat', age: 1 }, { animal: 'cat', age: 3 }, { animal: 'cat', age: 6 } ]

var updatedAnimals = animals.omit(function(i) {return i.age == 3});

console.log(updatedAnimals); // [ { animal: 'cat', age: 1 }, { animal: 'cat', age: 6 } ]

License

array.omit is licensed under the open source MIT license. View the LICENSE file for more information.

1.0.1

5 years ago

1.0.0

5 years ago