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

HTMLJavascriptProgramming Scripts

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>
raja
Published on 26-Feb-2018 12:33:18
Advertisements