javascript operator “in”

前端 未结 5 920
渐次进展
渐次进展 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条回答
  •  -上瘾入骨i
    2021-01-25 01:23

    1 is a valid vanilla numeric array index, x is not; in works with array indexes/object member names, not their values.

提交回复
热议问题