Home >>JavaScript Array Reference >JavaScript Array some() Method

JavaScript Array some() Method

JavaScript Array some() Method

JavaScript some() methodis used to check if atleast one of the elements in the given input array satisfies the condition provided as a function. It does not change the original given array.

Syntax:
array.some(function(currentValue, index, arr), thisValue)

Parameter Values

Parameter Description
currentValue This is a required parameter. It defines the value of the current element.
index This is an optional parameter. It defines the array index of the current element.
arr This is an optional parameter. It defines the array object the current element belongs to.
thisValue This is an optional parameter. It defines a value to be passed to the function to be used as its "this" value.

Browser Support

Method Chrome Edge Firefox Safari Opera
some() Yes 9.0 Yes Yes Yes
Here is an example of JavaScript some() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
var ages = [1, 100, 15, 250,123];
function checkAdult(age) 
{
  return age >= 100;
}
function myFunction() 
{
  document.getElementById("demo").innerHTML = ages.some(checkAdult);
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
var x = [1, 115, 15, 250,123];
function check(x) 
{
  return x >= 100;
}
function myFunction1() 
{
  document.getElementById("demo1").innerHTML = x.some(check);
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads