本文介绍了JavaScript的运营商QUOT;在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经习惯了蟒蛇,因此
A = [1,2,3]
1在一个# - >真正
B = [1,2,3,×]
在B#的x - >真正
为什么是它在JavaScript中
A = [1,2,3]
1在一个// - >真正
B = [1,2,3,×]
在B //X - >假
和更离奇
1,在B // - >真正
解决方案
在
适用于阵列,而不是价值的钥匙。 1在
成功,因为有你的阵列,它实际上是 2
值中的一个元素#1。
1
失败,因为没有 1
的属性或 KEY 您的阵列中的
详细位置:
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
解决方案
in
works on KEYS of arrays, not values. 1 in a
succeeds because there is an element #1 in your array, which is actually the 2
value.
"1"
fails, because there is no 1
PROPERTY or KEY in your array.
Details here: https://developer.mozilla.org/en/JavaScript/Reference/Operators/in
这篇关于JavaScript的运营商QUOT;在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!