Conclusion first
We cannot break
in forEach
loop
What are the alternatives
-
for of
: for...of - JavaScript | MDN
=> You might get eslint error
no-restricted-syntax - Rules - ESLint - Pluggable JavaScript linter
-
some
orevery
Here is the case with some()
Array.prototype.some() - JavaScript | MDN
returning true
break the loop 👍
Top comments (1)
Or just throw an exception inside the
forEach