Skip to content

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

  • by

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:

JavaScript array every method example

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

Leave a Reply

Your email address will not be published. Required fields are marked *