Created
October 4, 2017 10:56
-
-
Save kobeumut/637cabd70d0fc8df845d86ed48a7a851 to your computer and use it in GitHub Desktop.
For loop break is problem for foreach in Javascript. There is no built break in for each. You can do throw like that
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var exceptionOfBreak = {}; | |
| try { | |
| ["a", "b", "c"].forEach(function(el) { | |
| console.log(el); | |
| if (el === "b") throw exceptionOfBreak; | |
| }); | |
| } catch (e) { | |
| if (e == exceptionOfBreak) console.log("for loop is break"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment