Skip to content

Instantly share code, notes, and snippets.

@cange
Created September 28, 2010 09:55
Show Gist options
  • Save cange/600730 to your computer and use it in GitHub Desktop.
Save cange/600730 to your computer and use it in GitHub Desktop.
Find and remove an element from an array #learnjs
/**
* #learnjs
* Find and remove an element from an array #learnjs
*/
Array.prototype.remove = function (item) {
var pos = this.indexOf(item);
if (pos != -1) {
this.splice(pos, 1);
}
}
['one', 'two', 'three', 'four', 'five'].remove('three');
// result = ['one', 'two', 'four', 'five']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment