Jon
Rohan

I'm a front end web developer living in San Francisco. I have been coding HTML since I was 15. I strive to be the best I can at what I do. I believe in clean and simple design as well as code. This is where I represent myself on the web. I am always looking to form relationships with other amazing people, part time or full time. contact me!

Array.prototype.move2Back

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.

Tags: , , , 20 Jul 2009

About the Author, Jon Rohan

Hey! Thanks for stopping by. I love posting new topics here about various development things. If you liked it follow me on twitter and let me know.

Subscribe to Posts

Add comment