JavaScript .some()

acerslee's avatar
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.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

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:

Code
Output

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours