The some() methods perform testing and checks if atleast a single array element passes the test, implemented by the provided function. If the test is passed, it returns true. Else, returns false.
Note: If some() method is applied on an empty array, it returns false always.
callback_funct: It is the function that tests each element present in the array. It undertakes the following three arguments:
thisArg: It is an optional parameter, used as 'this' value while executing the callback function. If we do not provide, 'undefined' will be used as 'this' value.
It returns a boolean value. If it founds an element returning true value to the callback function, it returns true. Otherwise, false.
Note: The array.some() does not affect the original array.
Points to note:
Let's implement some examples to understand better:
Here's a simple implementation of the some() method.Test it Now
It tests whether any element is greater than 80. Thus, one element is present that is satisfying the condition. So, some() function returns True.
Testing if any array element contains the same match.Test it Now
Checking whether any array element is found even.Test it Now
We can also implement the above example using Arrow function.Test it Now
Note: If some() method finds the element matching the implemented condition of the callback function at first attempt, then it stops its search and returns Boolean true. It does not traverse for each element in that case.