Skip to content

Instantly share code, notes, and snippets.

@steppefox
Created June 13, 2013 06:47
Show Gist options
  • Save steppefox/5771683 to your computer and use it in GitHub Desktop.
Save steppefox/5771683 to your computer and use it in GitHub Desktop.
javascript in_array snippet like php function; needle (ru: игла) - what we want to find; haystack (ru: стог) - where;
function in_array(needle, haystack, strict) {
//original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
var found = false, key, strict = !!strict;
for (key in haystack) {
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
found = true;
break;
}
}
return found;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment