Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Array.prototype.some

Checks whether at least one element passes a test.

Available since: ES5

Syntax

array.some(callbackFn)

Parameters

ParameterTypeDescription
callbackFnFunctionA test function for an element.

Return value

boolean`true` if at least one element passed the test.

Examples

Is there a negative number:

console.log([3, -1, 5].some((n) => n < 0));

Output:

true

The companion every() checks that all elements match:

console.log([3, -1, 5].every((n) => n > 0));

Output:

false

Notes

For an empty array some() returns false and every() returns true.

See also

Related recipes

In the tutorial

  • Searching arrays — How to find an element in a JavaScript array: includes, indexOf, find, findIndex, some and every.

Thanks for reading!

Donate to the site — we work hard for you.