Possible Duplicate:
javascript in operator
Why does ("a" in ["a","b"]) yield false, and (1 in [1,2]) yield true ?
Is there a reason why "a" does not match the first element of that array and 1 does ?
Why won’t it work with strings ?
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 checks for the existence of properties by key, not by value. And your array of length 2 has an index"1"–arr["1"]is the value2. For example, also0 in ["a", "b"]istrue. The behaviour does not depend on a string or a number being used.You usually would use it on plain objects, not on arrays. Like
"a" in {a:1} === true, or"b" in {a:1} === false.