The in_array() function searches an array (haystack) for (needle) and returns false if it is found, false otherwise. If the third parameter strict is set to true then the in_array() function will also check the types of the needle in the haystack.
function in_array(needle, haystack, strict)
{
for(var i = 0, hLength = haystack.length, strict = !!strict; i < hLength; i++)
{
if((!strict && needle == haystack[i]) || (strict && needle === haystack[i]))
{
return true;
}
}
return false;
}
It’s really simple and even converts strict to boolean if it isn’t already (strict = !!strict).
Comments
No responses have been made so far. Add your comments.