【发布时间】:2017-03-27 01:45:49
【问题描述】:
在我拥有之前:
for (var i = 0; i < t1Children.length; i++) {
return checkIdentical( t1Children[i], t2Children[i] );
}
但我不知道如何使用 for 循环模式将每个“i”的 && 条件链接在一起。
以下内容按我想要的方式工作,但我需要继续手动添加 t2Children[2]、[3] 等。
return ( ( checkIdentical( t1Children[0], t2Children[0] ) ) && ( checkIdentical( t1Children[1], t2Children[1] ) ) );
如何以一种可以将 && 链接在一起的方式进行迭代?有什么建议吗?
【问题讨论】:
-
考虑将Array#every作为解决方案...
var result = t1Children.every((t1, index) => checkIdentical(t1, t2Children[index])); -
不确定您要做什么,您是否尝试将一个数组中的每个元素与另一个数组中的每个元素进行比较?
-
现在我想我明白你的意思了,看看答案
标签: javascript if-statement for-loop