Skip to content

Instantly share code, notes, and snippets.

@antics
Created November 11, 2010 09:33
Show Gist options
  • Save antics/672253 to your computer and use it in GitHub Desktop.
Save antics/672253 to your computer and use it in GitHub Desktop.
Searching a Javascript Array
// Index of
var arr=["one","two","three"];
arr.indexOf('two'); // 1
arr.indexOf('four'); // -1
// Prototyping
Array.prototype.exists = function(o) {
for(var i = 0; i < this.length; i++)
if(this[i] === o)
return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment