Created
September 28, 2010 09:55
-
-
Save cange/600730 to your computer and use it in GitHub Desktop.
Find and remove an element from an array #learnjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* #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