JS: Array.prototype.some

By Xah Lee. Date: . Last updated: .

Return true if the function f return true for at least one element.

This is done by evaluating f on each element in array in order. As soon as f(item) return true, exit the iteration and return true. Return false if none is true.

If myArray is empty, return false.

myArray must be a array object or array-like object. [see JS: Array-Like Object]

The function f is passed 3 args: • current_elementcurrent_indexmyArray.

If thisArg is given, it will be used as this value of f. If it is not given, undefined is used.

[see JS: “this” Binding]

// example of Array.prototype.some

const f = ((x) => (x === 3));

    [1,2,3,4,5,6].some(f) === true
// true

Use “some” as Loop with Break

“some” is useful as a forEach with break.

[see JS: Array.prototype.forEach]

Here's example. Apply f to each element in order. Exit the loop when f returns true.

// using Array.prototype.some as loop with break

function f (x) {
    console.log ( x );
    return x === 3 ;


// prints

// 1
// 2
// 3

// as soon as f returns true, the iteration aborts

「some」 on Empty Array

some on empty array returns false.

// method “some” on empty array returns false
        function (x) {return true;}
// false


[see JS: Array.prototype.every]

JS Array

  1. Understand JS Array
  2. Create Array
  3. Sparse Array
  4. Array-Like Object
  5. Array How-To

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials