
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
array-move
Advanced tools
The `array-move` npm package allows you to move an item in an array from one position to another. This can be useful for reordering lists or managing the positions of elements in an array.
Move an item within an array
This feature allows you to move an item from one index to another within the same array. In this example, the item at index 1 ('b') is moved to index 2.
const arrayMove = require('array-move');
const input = ['a', 'b', 'c'];
const result = arrayMove(input, 1, 2);
console.log(result); // ['a', 'c', 'b']
Move an item to the start of an array
This feature allows you to move an item to the start of the array. In this example, the item at index 2 ('c') is moved to index 0.
const arrayMove = require('array-move');
const input = ['a', 'b', 'c'];
const result = arrayMove(input, 2, 0);
console.log(result); // ['c', 'a', 'b']
Move an item to the end of an array
This feature allows you to move an item to the end of the array. In this example, the item at index 0 ('a') is moved to index 2.
const arrayMove = require('array-move');
const input = ['a', 'b', 'c'];
const result = arrayMove(input, 0, 2);
console.log(result); // ['b', 'c', 'a']
The `array-move-item` package also allows you to move items within an array. It is similar to `array-move` but may have different performance characteristics or additional utility functions.
Move an array item to a different position
$ npm install array-move
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']
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.
Moves the item to the new position in the array
array. Useful for huge arrays where absolute performance is needed.
Type: Array
Type: number
The index of item to move.
If negative, it will begin that many elements from the end.
Type: number
The index of where to move the item.
If negative, it will begin that many elements from the end.
FAQs
Move an array item to a different position
We found that array-move demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.