This is robust code which determines if a string exists in a JavaScript array. It returns true or false. If either parameter is invalid it throws an error.
stringInArray = function(s, a) { if ((s === undefined) || (a === undefined)) { throw "a or s is undefined"; } if (typeof s !== 'string') { throw "'" + s + "' is not a string"; } if (a.constructor !== Array) { throw "'" + a + "' is not an Array"; } if (s.length == 0) { throw "'" + s + "' is 0 length"; } return (a.indexOf(s) > -1); }