Array.prototype.move >= 0.1.4
Purpose
Move an array element from one array position to another
Syntax
Array#move
(
NumberoldIndex
NumbernewIndex
);
Parameters
oldIndex
newIndex
Return values
Array
this
Examples
Move based on indexes
var arr = Array.range(10);>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
arr.move(1, 7);>>> [0, 2, 3, 4, 5, 6, 7, 1, 8, 9]
Move based on values
var arr = ['a', 'b', 'c', 'd'];
arr.move('a', 'c');>>> ['b', 'c', 'a', 'd']
Enlarge arrays if needed
var arr = ['a', 'b', 'c'];
arr.move(0, 5);>>> ["b", "c", undefined, undefined, undefined, "a"]
Comments