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

What is the use of Array.Some() method in JavaScript?


Array.some()

Array.some() checks whether the given elements have passed the test implemented by the provided function(function given by user).Unlike Array.Every(), which returns true when all the elements passed the test, Array.some() will return true even one element in the array passed the test and returns false when every element failed the test.In the following example Array.some() checks whether any of the salary elements in array has crossed the given salary limit(15000) and  executes Boolean(true,false) output. 

Example

<html>
<body>
<p id="some1"></p>
<p id="some2"></p>
<script>
   var wages = [33000, 10000, 1000, 20000];
   var salary = [3000,9000,14000,10000]
   function checkSal(wage) {
      return wage >= 15000;
   }
   document.getElementById("some1").innerHTML = wages.some(checkSal);
   document.getElementById("some2").innerHTML = salary.some(checkSal);
</script>
</body>
</html>

Output

true
false