# array-move

> Move an array item to a different position

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

## Install

```sh
npm install array-move
pnpm add array-move
yarn add array-move
bun add array-move
```

## Health

**Score 43/100 (D)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2021-08-10 |
| First published | 2015-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/array-move) |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 427 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | array, move, change, position, index |

## Links

- npm: https://www.npmjs.com/package/array-move
- Repository: https://github.com/sindresorhus/array-move
- Homepage: https://github.com/sindresorhus/array-move#readme
- Issues: https://github.com/sindresorhus/array-move/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/array-move

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2021-08-10
- 3.0.1 — 2020-08-08
- 3.0.0 — 2020-07-12
- 2.2.2 — 2020-05-25
- 2.2.1 — 2019-12-01
- 2.2.0 — 2019-10-22
- 2.1.0 — 2019-04-02
- 2.0.0 — 2019-03-20
- 1.0.0 — 2015-09-08
- 0.1.0 — 2015-09-04

## README

# array-move

> Move an array item to a different position

## Install

```
$ npm install array-move
```

## Usage

```js
import {arrayMoveImmutable} from 'array-move';

const input = ['a', 'b', 'c'];

const array1 = arrayMoveImmutable(input, 1, 2);
console.log(array1);
//=> ['a', 'c', 'b']

const array2 = arrayMoveImmutable(input, -1, 0);
console.log(array2);
//=> ['c', 'a', 'b']

const array3 = arrayMoveImmutable(input, -2, -3);
console.log(array3);
//=> ['b', 'a', 'c']
```

## API

### arrayMoveImmutable(array, fromIndex, toIndex)

Clones the given `array`, moves the item to a new position in the new array, and then returns the new array. The given `array` is not mutated.

### arrayMoveMutable(array, fromIndex, toIndex)

Moves the item to the new position in the `array` array. Useful for huge arrays where absolute performance is needed.

#### array

Type: `Array`

#### fromIndex

Type: `number`

The index of item to move.

If negative, it will begin that many elements from the end.

#### toIndex

Type: `number`

The index of where to move the item.

If negative, it will begin that many elements from the end.

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