every javascript mdn code example
Example 1: foreach jas
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 2: js every
const exams = [80, 98, 92, 78, 77, 90, 89, 84, 81, 77]
exams.every(score => score >= 75)
Example 3: every in javascript
let data = [ {status: true}, {status: false}, {status: true} ]
let result = data.every((i) => {
return i.status === true
})
console.log(result)
Example 4: forEach
const arraySparse = [1,3,,7]
let numCallbackRuns = 0
arraySparse.forEach((element) => {
console.log(element)
numCallbackRuns++
})
console.log("numCallbackRuns: ", numCallbackRuns)
Example 5: js every
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].every(isBigEnough);
[12, 54, 18, 130, 44].every(isBigEnough);