Skip to content

Instantly share code, notes, and snippets.

@fcamblor
Created April 3, 2012 12:16
Show Gist options
  • Select an option

  • Save fcamblor/2291520 to your computer and use it in GitHub Desktop.

Select an option

Save fcamblor/2291520 to your computer and use it in GitHub Desktop.
// Array Remove - By John Resig (MIT Licensed)
// See http://ejohn.org/blog/javascript-array-remove/
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
// "Ghosting" remove function in order to not iterate over it during a for(.. in ..) loop
// on arrays
if(Object && Object.defineProperty){
// Will change "enumerable" metadata for Array.prototype.remove() function
Object.defineProperty(Array.prototype, "remove", { writable: false, enumerable: false });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment