Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

JavaScript can compare an array containing Boolean values using various logic operators such as AND (&&) or OR (||). For instance, to check if all the elements in the array are true, we can use the AND operator as follows:

let booleanArray = [true, true, false];
let allTrue = booleanArray.every(element => element); // returns false 

The every method checks if every element in the array satisfies the provided condition and returns a Boolean value. In the above code, allTrue variable will be false because the third element in the array is false. Similarly, to check if any element in the array is true, we can use the OR operator as follows:

let anyTrue = booleanArray.some(element => element); // returns true

The some method checks if any element in the array satisfies the provided condition and returns a Boolean value. In the above code, anyTrue variable will be true because at least one element in the array is true.