JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 279955
  • Score
    100M100P100Q164374F
  • License MIT

Move an array item to a different position

Package Exports

  • array-move

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-move) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

License

MIT © Sindre Sorhus