Agreed ;) Thank you for mentioning this. And throwing an exception can stop any kind of code.
Then this technique is a hack, it is not according to the design of the language like the break statement for imperative loops. Nor is it a feature of the forEach loop.
So throwing an exception in a forEach callback is possible, but when you reach that point in your code, refactoring to a for of or a for i loop would actually improve readability. :)
Yes totally agree as mentioned - though, we can wondering why such a break thing is not available for this method ? I mean, particularly, in the way to have a better understanding of the method itself and JavaScript more generaly...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
"Cannot Be Stopped" => It's possible to throw an exception to break the method if you really need, see that stackoverflow post
Thank you for the this reminder in the article !
Agreed ;) Thank you for mentioning this. And throwing an exception can stop any kind of code.
Then this technique is a hack, it is not according to the design of the language like the
break
statement for imperative loops. Nor is it a feature of theforEach
loop.So throwing an exception in a
forEach
callback is possible, but when you reach that point in your code, refactoring to afor of
or afor i
loop would actually improve readability. :)Yes totally agree as mentioned - though, we can wondering why such a break thing is not available for this method ? I mean, particularly, in the way to have a better understanding of the method itself and JavaScript more generaly...