some() method

The some() method will check if any element in a given array passes a supplied test (with a function). If it finds an element which passes the test, it'll stop there and will not run further (and will return true). Otherwise, it'll return false.

Here's an example:

const arr = [1, 3, 5, 7, 9, 10, 11];const isAnyElementEven = arr.some( elem => {    console.log('Checking '+elem);    return elem % 2 == 0});console.log(isAnyElementEven); // true

The output is as follows:

Checking 1Checking 3Checking 5Checking 7Checking 9Checking 10true

Notice that it stops at 10 once the test is passed.

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.