The .some()
method allows us to check if at least one element in an array passes a specified test.
Syntax:
- callback: A function with the test to be applied on each element of the array.
- element: The current element being processed in the array.
- index - optional: The index of the current element being processed.
- array - optional: The array
.some()
was called upon.
.some()
returns true if the callback function
returns true for at least one element,
otherwise, it returns false.
In this example, we have passed a function to .some()
method that checks if the given number is even. Since 2 is an even number in the numberSet1
array, the callback function returns true for it
and thus .some()
method returns true.
In the second example as there are no zeros in the numberSet2
array, the callback function returns false every single time and thus the .some()
method returns false.