I’m used to python, so
a = [1,2,3]
1 in a # -> True
b = ["1", "2", "3", "x"]
"x" in b # -> True
Why is it that in JavaScript
a = [1,2,3]
1 in a // -> true
b = ["1", "2", "3", "x"]
"x" in b // -> false
and much weirder
"1" in b // -> 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.
inworks on KEYS of arrays, not values.1 in asucceeds because there is an element #1 in your array, which is actually the2value."1"fails, because there is no1PROPERTY or KEY in your array.Details here: https://developer.mozilla.org/en/JavaScript/Reference/Operators/in