Skip to content

Instantly share code, notes, and snippets.

@philhawksworth
Created February 22, 2010 18:40
Show Gist options
  • Save philhawksworth/311336 to your computer and use it in GitHub Desktop.
Save philhawksworth/311336 to your computer and use it in GitHub Desktop.
Array.prototype.contains = function(item) {
return this.indexOf(item) != -1;
};
var a = ['foo', 'bar', 'baz'];
alert(a.contains('bar'));
// Handy but arguably not always a good idea...
// String.prototype and Array.prototype are themselves global namespaces, and adding properties to them brings the same risk of collisions as being careless with regular globals...
// -- http://simonwillison.net/2007/Aug/15/jquery/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment