.some()
Published Jul 11, 2023
Contribute to Docs
The .some()
method tests whether at least one item in the array passes the test implemented by the provided function. It returns true if any item in the array succeeds the test, otherwise it returns false.
Syntax
array.some(callback);
callback
: A function that takes in an element as a parameter. The element is then determined if it passes or fails the test.
Example
In the example below the .some()
function is used to determine if any of the values in the array are even (divisible by 2).
const numbers = [2, 4, 5, 7, 8];const callback = (element) => element % 2 === 0;console.log(numbers.some(callback));
This example results in the following output:
true
Codebyte Example
Below are two examples of running the .some()
function on the numbers
array:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.