Created
March 31, 2010 23:56
-
-
Save schwanksta/351116 to your computer and use it in GitHub Desktop.
Javascript doesn't have an "in" operator, so you can use this in_array function instead.
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
function in_array(val, arr, sep){ | |
/* Takes an array, joins it using sep (default = '|'), then | |
* uses indexOf to test if val is in arr. Returns true or false. | |
*/ | |
if(!sep){ | |
var sep = "|"; | |
} | |
var join = ["", arr.join(sep), ""].join(sep); | |
var retc = join.indexOf(val); | |
return retc != -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment