check if every value in array is true code example
Example 1: javascript check if any value in array is true
let boolArray1 = [true, false, false]
let boolArray2 = [false, false, false]
boolArray1.some(x => x);
boolArray2.some(x => x);
let numberArray = [1, 2, 3, 4, 5];
let oddNumbers = [1, 3, 5, 7, 9];
const even = (element) => element % 2 === 0;
numberArray.some(even);
oddNumbers.some(even);
Example 2: check if all elements in array are true javascript
You can use `every()` array method
let data = [ {status: true}, {status: false}, {status: true} ]
let result = data.every((i) => {
return i.status === true
})
console.log(result)
let data = [ {status: true}, {status: true}, {status: true} ]
let result = data.every((i) => {
return i.status === true
})
console.log(result)
Example 3: javascript every
const age= [2,7,12,17,21];
age.every(function(person){
return person>18;
});
const age= [2,7,12,17,21];
age.every((person)=> person>18);
Example 4: javascript every method
let numbers = [1, 2, 3, 42, 3, 2, 4, -1];
let allPassed = numbers.every(function(element){
return element > 0;
});