Skip to content

Instantly share code, notes, and snippets.

@dshaw
Created April 23, 2010 19:07
Show Gist options
  • Save dshaw/377011 to your computer and use it in GitHub Desktop.
Save dshaw/377011 to your computer and use it in GitHub Desktop.
Array.prototype.remove( element )
// Check to make sure indexOf is implemented (!!IE6).
if (!Array.indexOf) {
Array.prototype.indexOf = function(elem) {
var i=0,
length=this.length;
for (; i < length; i++) {
if (this[i] === elem ) {
return i;
}
}
return -1;
};
}
// Add remove method to Array.
Array.prototype.remove = function(elem) {
return this.splice(this.indexOf(elem), 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment