javascript operator “in”

前端 未结 5 919
渐次进展
渐次进展 2021-01-25 00:56

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

5条回答
  •  深忆病人
    2021-01-25 01:08

    Because "x" in b is looking for a property name 'x'. There is none, they are all numerical (but still string) property names, considering it is an array.

提交回复
热议问题