https://github.com/writetome51/array-get-and-remove-by-indexes
Removes and returns items from array, identified by their indexes
https://github.com/writetome51/array-get-and-remove-by-indexes
array-manipulations elements javascript remove typescript
Last synced: 15 days ago
JSON representation
Removes and returns items from array, identified by their indexes
- Host: GitHub
- URL: https://github.com/writetome51/array-get-and-remove-by-indexes
- Owner: writetome51
- License: mit
- Created: 2018-10-31T07:12:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-02T16:05:48.000Z (about 5 years ago)
- Last Synced: 2025-02-02T17:05:04.509Z (over 1 year ago)
- Topics: array-manipulations, elements, javascript, remove, typescript
- Language: JavaScript
- Size: 50.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getAndRemoveByIndexes\(
indexes: number[],
array: T[]
): T[]
Removes and returns items, identified by their `indexes`, from `array`.
Negative indexes not allowed.
Items are returned in ascending index-order: i.e, item with index 0 appears first.
## Examples
```js
let arr = [10,20,30,40,50,60];
let removed = getAndRemoveByIndexes([3, 1], arr);
// removed is now [20, 40]. arr is now [10, 30, 50, 60].
arr = ['he', 'llo', 'zz', 'gg', 'cc'];
removed = getAndRemoveByIndexes([4, 0], arr);
// removed is now ['he', 'cc']. arr is ['llo', 'zz', 'gg'].
arr = [10,20,30,40,50,60];
removed = getAndRemoveByIndexes([1,3,5], arr);
// removed is now [20, 40, 60]. arr is [10, 30, 50].
// It can work with duplicate indexes, though the result may not be
// what you wanted:
arr = ['he', 'llo', 'zz', 'gg', 'cc', 'aa'];
removed = getAndRemoveByIndexes([2, 3, 4, 4], arr);
// removed is now ['zz', 'gg', 'aa', 'cc']. arr is ['he', 'llo']
arr = ['he', 'llo', 'zz', 'gg', 'cc', 'aa'];
removed = getAndRemoveByIndexes([1, 1, 1], arr);
// removed is now ['gg', 'zz', 'llo']. arr is ['he', 'cc', 'aa']
```
## Installation
`npm i @writetome51/array-get-and-remove-by-indexes`
## Loading
```js
import {getAndRemoveByIndexes}
from '@writetome51/array-get-and-remove-by-indexes';
```