What is the some() method?

The some() method checks if any of the elements in an array pass a given test that’s provided as a function. It also checks if the some()method returns a True or False boolean value.

Syntax

array.some(testfunction)
<!DOCTYPE html>
<html>
<body>
<p>Click the button to check if any of the chocolates is "Mars".</p>
<button onclick="myfunc()">Click</button>
<p id="demo"></p>
<script>
// defining a list of chocolates
var chocolates = ["Mars", "Hersheys", "Kitkat", "Twix"];
// defining our functions
function checkMars(choc) {
return choc == "Mars";
}
// this function uses array some method and takes in
// our function checkMars as an argument. This will return
// a value true of false.
function myfunc() {
document.getElementById("demo").innerHTML = chocolates.some(checkMars);
}
</script>
</body>
</html>

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved