Skip to content

Instantly share code, notes, and snippets.

@davidrautert
Created November 8, 2011 20:02
Show Gist options
  • Save davidrautert/1348984 to your computer and use it in GitHub Desktop.
Save davidrautert/1348984 to your computer and use it in GitHub Desktop.
js prototype of shift function
if(!Array.prototype.shift) { // if this method does not exist..
Array.prototype.shift = function(){
firstElement = this[0];
this.reverse();
this.length = Math.max(this.length-1,0);
this.reverse();
return firstElement;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment