JavaScript: Array.prototype.some

By Xah Lee. Date: . Last updated: .
arrayX.some(f)
Return true if the function f return true for at least one element. As soon as f return true, exit the iteration and return true. If array is empty, return false.
arrayX can be Array-Like Object.
The function f is passed 3 args: • current_elementcurrent_indexarrayX.
arrayX.some(f, thisArg)
Use thisArg for this Binding of f
const ff = (x => (x === 3));
console.log( [1,2,3,4,5,6].some(ff) ); // true

Use “some” as Loop with Break

some is useful as a forEach with break.

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

const ff = (x => { console.log( x ); return x === 3 ; });
[1,2,3,4,5,6].some(ff)
// prints
// 1
// 2
// 3

「some」 on Empty Array

some on empty array returns false.

console.log( [].some (x => true) ); // false
JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Array

prototype