我想根据可扩展的变量数组检查多个条件。检查方法是什么?
例如:
a = 0;
b = 1;
c = 0;
if (a == 0 && b == 0 && c == 0) {
console.log("all a,b,c variables == 0")
}
好。现在要一个数组吗?
arr = ["a", "b", "c", "d", ...];
if (for i = 0; i < arr.length; i ++ { arr[i] == 0 && }) {
console.log("all arr variables == 0")
}
我想我走错了路...有没有解决方案检查基于数组的大量语句?
感谢您的帮助。
最佳答案
const array = [0, 0, 0];
array.every(x => x === 0); // true
关于JavaScript : loop in conditional based on array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36846376/