I decided to write a javascript prototype function for the Array class called move2Back. This will move the nth object in the array to the back of the array. For example when I do this.
var arr = [1,2,"A",4,5];
arr.move2Back(2);
Then the array becomes:
[1,2,4,5,"A"]
This is the small javascript function that accomplishes the task.
/*
* This function moves the nth member of the array to the end
*/
Array.prototype.move2Back = function(n) {
this.push(this.splice(n,1).pop());
return this;
}
var arr = ["Jani","Hege","Stale","Kai Jim","Borge","Tove"];
console.log(arr.move2Back(3));
If you enjoyed reading this post, check out this post Submit to Digg Bookmarklet.