列表中的 javascript 字符串返回 false

Nix*_*Nix 4 javascript

我的网站刚刚开始为以下 javascript 检查返回 false。我试图理解为什么。

_test = ["0e52a313167fecc07c9507fcf7257f79"]
"0e52a313167fecc07c9507fcf7257f79" in _test
>>> false
_test[0] === "0e52a313167fecc07c9507fcf7257f79"
>>> true 
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我理解为什么吗?

Bar*_*art 8

运算in符测试属性是否在对象中。例如

var test = {
    a: 1,
    b: 2 
};

"a" in test == true;
"c" in test == false;
Run Code Online (Sandbox Code Playgroud)

您想要测试数组是否包含特定对象。您应该使用 Array#indexOf 方法。

test.indexOf("0e52...") != -1 // -1 means "not found", anything else simply indicates the index of the object in the array.
Run Code Online (Sandbox Code Playgroud)

MDN 上的 Array#indexOf:https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf