Skip to content

Instantly share code, notes, and snippets.

@decnorton
Last active December 19, 2015 16:29
Show Gist options
  • Save decnorton/5983922 to your computer and use it in GitHub Desktop.
Save decnorton/5983922 to your computer and use it in GitHub Desktop.
Adds .remove() method to Array.
/**
* Array Remove
*
* Based on code by John Resig http://ejohn.org/blog/javascript-array-remove/
*/
Array.prototype.remove = function(from, to) {
// If first arg is not a number, try and find it in the array
if(isNaN(from)) {
from = this.indexOf(from);
if(from < 0) {
return;
}
}
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment