Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

What is the some() method?

Sarvech Qadir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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>

RELATED TAGS

javascript

CONTRIBUTOR

Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring