1let boolArray1 = [true, false, false]
2let boolArray2 = [false, false, false]
3
4boolArray1.some(x => x); // true
5boolArray2.some(x => x); // false
6
7// Example of using a function to evaluate array
8let numberArray = [1, 2, 3, 4, 5];
9let oddNumbers = [1, 3, 5, 7, 9];
10
11// checks whether an element is even
12const even = (element) => element % 2 === 0;
13
14numberArray.some(even); // true
15oddNumbers.some(even); // false
16
1You can use `every()` array method
2
3let data = [ {status: true}, {status: false}, {status: true} ]
4let result = data.every((i) => {
5 return i.status === true
6})
7console.log(result) // false
8
9let data = [ {status: true}, {status: true}, {status: true} ]
10let result = data.every((i) => {
11 return i.status === true
12})
13console.log(result) // true
1// array.every(function(elemnt)) method takes in a function
2// which evaulates each elment
3// The every method is designed to check if all the elements
4// in an array meet a specific condition
5// This condition is defined within your function
6
7let numbers = [1, 2, 3, 42, 3, 2, 4, -1];
8
9let allPassed = numbers.every(function(element){
10 return element > 0;
11});
12
13// This method returns a Boolean value
14// allPassed is set to false because not all elements were greater than 0
15
16
1const age= [2,7,12,17,21];
2age.every(function(person){
3return person>18;
4}); //false
5
6//es6
7const age= [2,7,12,17,21];
8age.every((person)=> person>18); //false