JavaScript array every method | checks if all elements pass a test

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 array are true JavaScript:-

In the example we are checking weather all marks are greater then 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:

JavaScript array every method example

Do comment if you have any doubts and suggestion 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


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.