【发布时间】:2019-02-28 12:38:17
【问题描述】:
<!DOCTYPE HTML>
<html>
<body>
<p>Before the script...</p>
<script>
alert([[25,4]].includes([25,4]));
</script>
<p>...After the script.</p>
</body>
</html>
当我运行上面的代码时,它输出“false”,这是不正确的。如果我将 [[25,4]].includes([25,4]) 更改为 ['a'].includes('a'),它会输出正确答案“true”。为什么这样做?
【问题讨论】:
-
includes测试严格相等,这意味着两个数组需要是同一个数组,而不是恰好保存相同值的两个数组。由于[[25,5]] === [[25,5]]为假的相同原因,它不起作用。 -
var tuple = [25, 24]; alert([tuple].includes(tuple))你去吧
标签: javascript