Created
July 14, 2012 14:39
-
-
Save toruta39/3111671 to your computer and use it in GitHub Desktop.
Search str in arr by either exact match or not
This file contains 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
//Search str in arr by either exact match or not | |
function searchArray(str, arr, exactMatch) { | |
if (exactMatch) { | |
//Search for the exact same item with str in arr | |
for (var i = 0; i < arr.length; i++) { | |
if (str == arr[i]) { | |
return true; | |
} | |
} | |
} else { | |
//Search for any item that contains str | |
return arr.join(" ").indexOf(str) > -1; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment