Skip to content

Instantly share code, notes, and snippets.

@matheuslc
Created August 29, 2014 17:23
Show Gist options
  • Save matheuslc/a814cd2c00f9368698e4 to your computer and use it in GitHub Desktop.
Save matheuslc/a814cd2c00f9368698e4 to your computer and use it in GitHub Desktop.
A value have in array
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
@matheuslc
Copy link
Author

Don't pollute the built-in prototype. Thanks @rafaelnardini.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment