Skip to content

Instantly share code, notes, and snippets.

@krutz27
Created October 4, 2013 13:30
Show Gist options
  • Save krutz27/6825936 to your computer and use it in GitHub Desktop.
Save krutz27/6825936 to your computer and use it in GitHub Desktop.
//jQuery version
jQuery.inArray("value", arr); // Usage: if( jQuery.inArray("value", arr) != -1 ) { true };
//Javascript version
Array.prototype.inArray = function (value) {
var i;
for (i=0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
};
//[1,2,3].inArray(2) > true
//[1,2,3].inArray(22) > false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment