I have an array with boolean values:
var array = [false, false, false];
I want to execute a function only if all the elements are false.
I tried this and it didn’t work, because it would execute the function for every false:
for(var i = 0; i < array.length; i++){
if(array[i] === false){
functionA(); //This function ran at every false
}else{
//Do something else
}
}
The
indexOffunction returns the first index at which a given element can be found in the array, or -1 if it is not present.