# @writetome51/array-remove-by-indexes

> Removes items from array, identified by indexes

Latest version **4.0.0** (published 2021-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writetome51/array-remove-by-indexes
pnpm add @writetome51/array-remove-by-indexes
yarn add @writetome51/array-remove-by-indexes
bun add @writetome51/array-remove-by-indexes
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-10-26 |
| First published | 2018-11-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | array, remove, items, index, indexes, manipulation |

## Links

- npm: https://www.npmjs.com/package/@writetome51/array-remove-by-indexes
- Repository: https://github.com/writetome51/array-remove-by-indexes
- Homepage: https://github.com/writetome51/array-remove-by-indexes#readme
- Issues: https://github.com/writetome51/array-remove-by-indexes/issues
- npm.io page: https://npm.io/package/@writetome51/array-remove-by-indexes

## Dependencies (3)

- [@writetome51/get-array-copy](https://npm.io/package/@writetome51/get-array-copy.md) >=1.0.0
- [@writetome51/order-numerically](https://npm.io/package/@writetome51/order-numerically.md) >=1.0.0
- [@writetome51/array-get-and-remove-by-index](https://npm.io/package/@writetome51/array-get-and-remove-by-index.md) >=2.0.0

## Recent versions

- 4.0.0 (latest) — 2021-10-26
- 3.1.0 — 2020-09-06
- 3.0.0 — 2020-08-31
- 2.0.0 — 2020-08-06
- 1.0.2 — 2019-03-01
- 1.0.1 — 2018-12-07
- 1.0.0 — 2018-11-02

## README

# removeByIndexes\<T\>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;indexes: number[],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;array: T[],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;useRemovedItem?: (item: T) => void<br>): void

Removes items, identified by `indexes`, from `array`.   
Negative indexes not allowed.  
Optional callback `useRemovedItem()` lets you collect each removed item  
for further manipulation.  
The algorithm first sorts `indexes` in ascending order. Then the items of  
`array` are removed in descending index order, i.e., item with index 0 would  
be removed last.

## Examples
```js
let arr = [10,20,30,40,50,60];
removeByIndexes([3, 1], arr);
// arr is now [10, 30, 50, 60].


arr = ['he', 'llo', 'zz', 'gg', 'cc'];
let removed = [];

removeByIndexes([4, 0], arr, (item) => removed.push(item));
// removed is ['cc', 'he'] (remember, elements are removed in descending index order).
// arr is ['llo', 'zz', 'gg']. 


arr = [10,20,30,40,50,60];
removed = [];

removeByIndexes([1, 3, 5], arr, (item) => removed.push(item));
// removed is [60, 40, 20]
// 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'];
removeByIndexes([2, 3, 4, 4], arr);
// arr is ['he', 'llo']

arr = ['he', 'llo', 'zz', 'gg', 'cc', 'aa'];
removeByIndexes([1, 1, 1], arr);
// arr is ['he', 'cc', 'aa']

// Don't pass string numbers. You'll get confusing errors or unexpected results.
removeByIndexes(['1'], arr);
// Error: "the array does not have enough items to fulfill your request"
```

## Installation
`npm i  @writetome51/array-remove-by-indexes`

## Loading
```js
import {removeByIndexes} from '@writetome51/array-remove-by-indexes';
```

---
_Source: https://npm.io/package/@writetome51/array-remove-by-indexes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
