Just make a simple js object instead of an array.
var whitelist = { "string1":true, "string2":true }
and then you can just check if(whitelist[str]) to check if this is available.
Or use if(str in whitelist) .
I expect the former to have slightly better performance (I have not tested this), but the latter is more readable and makes the goal understandable. Thus, your choice of them is better suited.
Ben mccormick
source share