Computer >> Computer tutorials >  >> Programming >> Javascript

What is the usage of some() method in JavaScript?


To add a test for the elements of the array, such as checking voter age, etc, then use the JavaScript some() method.

Example

You can try to run the following code to learn how to work with some() method in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <script>
         var voter_ages = [17, 15, 19, 16, 20];
            function voterAge(myAge) {
               return myAge >= 18;
            }
            document.write("Minimum Voter Age in the list: "+voter_ages.some(voterAge));
      </script>
   </body>
</html>