- Learning JavaScript Data Structures and Algorithms
- Loiane Groner
- 91字
- 2021-08-27 18:41:16
Iterating using the some method
Next, we have the some method. It has the opposite behavior to the every method; however, the some method iterates each element of the array until the return of the function is true:
numbers.some(isEven);
In our case, the first even number of our numbers array is 2 (the second element). The first element that will be iterated is the number 1; it will return false. Then, the second element that will be iterated is the number 2, which will return true, and the iteration will stop.