On a sidenote, I often use a similar method to check if a string exists in an array of strings by making the stringArray a Regular Expression.
It's especially useful if the array changes dynamically between tests.
^ means the beginning of the testString, $ means the end, and | means "or".
The "i" means it ignores upper/lower case.
javascript Code:
var theStrings = ['String A','String B','String C'];
function exists(testString)
{
return new RegExp("^"+theStrings.join("$|^")+"$","i").test(testString);
// Evaluates to the same as /^String A$|^String B$|^String C$/i.test(testString)
}