Possible Duplicate:
Javascript – array.contains(obj)
What’s wrong with this:
var zipCodes =(['90001','90002','90003']);
Test if the value exists in the array zipCodes
if('90001' in zipCodes) {
alert('True');
};
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
inoperator looks at property names, not values.Because it’s an Array, the property names will be the indices of the Array.
If you’re only supporting a modern environment, you could use
Array.prototype.indexOf().If you need to support environments that don’t have
.indexOf(), you could implement the MDN fix.