Skip to content

Instantly share code, notes, and snippets.

@toruta39
Created July 14, 2012 14:39
Show Gist options
  • Save toruta39/3111671 to your computer and use it in GitHub Desktop.
Save toruta39/3111671 to your computer and use it in GitHub Desktop.
Search str in arr by either exact match or not
//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