我有一个布尔值列表。我要申请||
(“或”)对每个,并得到结果。 (所以,一个新的布尔值。)
该列表没有固定长度,所以我不能简单地将代码写为value = l[0] || ... l[length-1]
。 (对于长列表来说,这也会很丑陋。)
我的做法:
let index = 0;
let value = true;
while(index < list.length && value == value || list[index]) {
index += 1;
}
我想这作为一种说法是可能的。如何?
你可以使用.includes https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes,它检查数组是否包含值,并返回true
/ false
const list = [true, true, true, true, false];
// Checks if list contains the Boolean True
const value = list.includes(true);
console.log(value);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)