https://github.com/mafintosh/unordered-array-remove
Efficiently remove an element from an unordered array without doing a splice
https://github.com/mafintosh/unordered-array-remove
Last synced: 9 months ago
JSON representation
Efficiently remove an element from an unordered array without doing a splice
- Host: GitHub
- URL: https://github.com/mafintosh/unordered-array-remove
- Owner: mafintosh
- License: mit
- Created: 2015-12-30T14:31:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-01-05T04:18:54.000Z (over 4 years ago)
- Last Synced: 2025-06-26T22:19:03.871Z (10 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 118
- Watchers: 3
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-micro-npm-packages - unordered-array-remove - Efficiently remove an element from an unordered array without doing a splice. (Modules / Array)
- awesome-micro-npm-packages-zh - unordered-array-remove - 在不进行splice的情况下,有效地从无序数组中移除元素. (模块 / 数组)
- awesome-micro-npm-packages - unordered-array-remove - Efficiently remove an element from an unordered array without doing a splice. (Modules / Array)
- awesome-micro-npm-packages - unordered-array-remove - Efficiently remove an element from an unordered array without doing a splice. (Modules / Array)
README
# unordered-array-remove
Efficiently remove an element from an unordered array without doing a splice
```
npm install unordered-array-remove
```
[](http://travis-ci.org/mafintosh/unordered-array-remove)
## Usage
``` js
var remove = require('unordered-array-remove')
var list = ['a', 'b', 'c', 'd', 'e']
remove(list, 2) // remove 'c'
console.log(list) // returns ['a', 'b', 'e', 'd'] (no 'c')
```
This works by popping the last element (which is fast because it doesn't need shift all array elements)
and overwriting the removed index with this element.
## License
MIT