Created
August 29, 2014 17:23
-
-
Save matheuslc/a814cd2c00f9368698e4 to your computer and use it in GitHub Desktop.
A value have in array
This file contains 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
var arr = ['foo', 'bar']; | |
Array.prototype.has = function(value) { | |
return this.indexOf(value) >= 0; | |
} | |
arr.has('foo'); // true | |
arr.has('bar'); // true | |
arr.has('baz'); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't pollute the built-in prototype. Thanks @rafaelnardini.