Created
November 11, 2010 09:33
-
-
Save antics/672253 to your computer and use it in GitHub Desktop.
Searching a Javascript Array
This file contains hidden or 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
// 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