Answers for "check if all elements in array are true javascript"

2

javascript check if any value in array is true

let boolArray1 = [true, false, false]
let boolArray2 = [false, false, false]

boolArray1.some(x => x);  // true
boolArray2.some(x => x);  // false

// Example of using a function to evaluate array
let numberArray = [1, 2, 3, 4, 5];
let oddNumbers = [1, 3, 5, 7, 9];

// checks whether an element is even
const even = (element) => element % 2 === 0;

numberArray.some(even);  // true
oddNumbers.some(even);   // false
Posted by: Guest on October-01-2020
1

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) // false

let data = [ {status: true}, {status: true}, {status: true} ]
let result = data.every((i) => {
	return i.status === true
})
console.log(result) // true
Posted by: Guest on March-25-2021
8

javascript every method

// array.every(function(elemnt)) method takes in a function 
// which evaulates each elment 
// The every method is designed to check if all the elements
// in an array meet a specific condition 
// This condition is defined within your function

let numbers = [1, 2, 3, 42, 3, 2, 4, -1];

let allPassed = numbers.every(function(element){
	return element > 0;
});

// This method returns a Boolean value
// allPassed is set to false because not all elements were greater than 0
Posted by: Guest on March-05-2020
9

javascript every

const age= [2,7,12,17,21];
age.every(function(person){
return person>18;
});  //false

//es6
const age= [2,7,12,17,21];
age.every((person)=> person>18);  //false
Posted by: Guest on June-12-2020

Code answers related to "check if all elements in array are true javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language