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
1const exams = [80, 98, 92, 78, 77, 90, 89, 84, 81, 77]
2exams.every(score => score >= 75) // Say true if all exam components are greater or equal than 75
1let data = [ {status: true}, {status: false}, {status: true} ]
2let result = data.every((i) => {
3 return i.status === true
4})
5console.log(result) // false
1function isBigEnough(element, index, array) {
2 return element >= 10;
3}
4[12, 5, 8, 130, 44].every(isBigEnough); // false
5[12, 54, 18, 130, 44].every(isBigEnough); // true
6
1[12, 5, 8, 130, 44].every(x => x >= 10); // false
2[12, 54, 18, 130, 44].every(x => x >= 10); // true