【发布时间】:2018-07-02 06:25:51
【问题描述】:
我正在尝试通过函数 indexOf 查找我的数组的索引,但我无法得到正确的结果。
var points =[
["2.408","38.8"],
["2.410","38.8"],
["2.410","38.76"]
];
var position = points.indexOf(["2.408","38.8"]);
我认为它应该返回 0 而不是 -1,所以我将这两个数组作为打击。
console.log(points[0]===["2.408","38.8"])
然后我错了。
我不明白为什么这不是真的。
感谢您的建议...
【问题讨论】:
-
"indexOf() compares searchElement to elements of the Array using strict equality (the same method used by the === or triple-equals operator)." 所以你试试
console.log(["2.408","38.8"]===["2.408","38.8"])现在你明白为什么它失败了。
标签: javascript arrays indexing