Depends on the function. In the specific case of forEach
the answer is no. This is explained on the documentation:
There is no way to stop or break a forEach() loop other than by
throwing an exception. If you need such behavior, the forEach() method
is the wrong tool.
Early termination may be accomplished with:
- A simple for loop
- A for...of / for...in loops
- Array.prototype.every()
- Array.prototype.some()
- Array.prototype.find()
- Array.prototype.findIndex()
Array methods: every(), some(), find(), and findIndex() test the array
elements with a predicate returning a truthy value to determine if
further iteration is required.