JavaScript some()
Syntax
array.some(function(currentValue, index, arr), thisValue)
- The
some()
method is called on an array and accepts one required argument, a callback function. - This callback function takes three arguments:
- The
currentValue
represents the value of the array elements. - The
index
argument is optional and represents the current index of the elements. - The
arr
argument is optional and represents the array itself.
- The
- The
thisValue
parameter is optional and represents the value ofthis
when the callback function is executed.
Example
Consider the following example,
const numbers = [2, 4, 6, 8, 10];
const numberExists = numbers.some((number) => number === 6);
console.log(numberExists);
Output
The output return true
as the callback function found an element that matches the condition.