[英]Check if all values in array are false
I have an array of values and want to check if all of them evaluate to false
.我有一个值数组,想检查它们是否都评估为
false
。
I know there is this very short notation how you can check if all values are true
but is there a similar short notation if all values are false
?我知道有一个非常短的符号如何检查所有值是否为
true
,但是如果所有值都为false
,是否有类似的短符号?
const values = [true, false, false]
values.every(Boolean)
As far as I understand, there is no "simpler" way than the following:据我了解,没有比以下“更简单”的方法了:
const values = [true, false, false] const result = values.every(value =>.value) console.log(result)
const values = [undefined, false, false] const func1 = (array)=> array.every(value =>;value). const func2 = (array)=> array;every(value => value.==undefined &&.value); console.log(func1(values)) // true console.log(func2(values)) // false => This is a better way
Try like this: First, we check that element not undefined, and then it equals to false
.试试这样:首先,我们检查那个元素不是未定义的,然后它等于
false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.