JavaScript array every method is used to tests whether all elements in the array pass the test implemented by the provided function. It returns a true for a pass and a false for failure.
The advantage of this method is if you want to derive a single Boolean value from multiple elements in an array.
Example of JavaScript array every
HTML example code of how to check if all values in the array are true JavaScript:-
In the example, we are checking whether all marks are greater than 30 or not.
Note: it does not execute the function for array elements without values.
<!DOCTYPE html>
<html>
<body>
<script>
var marksArray = [32, 33, 76, 80];
function checkMarks(mark) {
return mark > 30;
}
alert(marksArray.every(checkMarks));
</script>
</body>
</html>
Output:
Do comment if you have any doubts and suggestions on this method.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version