array-move
Move an array item to a different position
Last updated 6 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm
$ cnpm install array-move 
SYNC missed versions from official npm registry.

array-move Build Status

Move an array item to a different position

Install

$ npm install array-move

Usage

const arrayMove = require('array-move');

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

arrayMove(input, 1, 2);
//=> ['a', 'c', 'b']

arrayMove(input, -1, 0);
//=> ['c', 'a', 'b']

arrayMove(input, -2, -3);
//=> ['b', 'a', 'c']

API

arrayMove(array, from, to)

Returns a new array with the item moved to the new position.

arrayMove.mutate(array, from, to)

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

array

Type: Array

from

Type: number

Index of item to move. If negative, it will begin that many elements from the end.

to

Type: number

Index of where to move the item. If negative, it will begin that many elements from the end.

Current Tags

  • 4.0.0                                ...           latest (4 years ago)

3 Versions

  • 4.0.0                                ...           4 years ago
  • 3.0.1                                ...           5 years ago
  • 2.2.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org