If I have an array of boolean values, what is the cleanest/best way to check whether ANY values of the array are true?
[true, true, true] <-- want this to return true
[true, false, true] <-- want this to return true
[false, false, false] <-- want this to return false
[false, false, true] <-- want this to return true
I was reading about the "some" function of arrays and was thinking that might be what I want, but it requires a "callback function". It feels strange to have to write a function that only checks whether an input is true or false.
I am sure there is something obvious/simple that I'm missing.
Open to any ideas or help!
[true, true, true] <-- want this to return true
[true, false, true] <-- want this to return true
[false, false, false] <-- want this to return false
[false, false, true] <-- want this to return true
I was reading about the "some" function of arrays and was thinking that might be what I want, but it requires a "callback function". It feels strange to have to write a function that only checks whether an input is true or false.
Code:
function checkTrue(val) {
return val;
}
console.log([true, false, true].some(checkTrue));
// This works but feels awkward...
// I would rather not define a new function here
Open to any ideas or help!