知らなかったのでメモ。 JavaScript1.6からの配列のメソッドforEachですが、ループを途中で止めるには例外を使うしかありません。 例えば以下のコードは1,3,4,5が表示されます。returnにはcontinue相当の効果がありますが、ループを途中で止めることはできません。 [1,2,3,4,5].forEach(function(val){ if (val==2) { return; } alert(val); }); forEach - MDC Docsによる解説を見ると、内部実装的には以下のコードになっているそうで if (!Array.prototype.forEach) { Array.prototype.forEach = function(fun /*, thisp*/){ var len = this.length; if (typeof fun != "fu
![Array.prototype.forEachは止まらない](https://cdn-ak-scissors.b.st-hatena.com/image/square/126e9c63960837b5815901e11e1f6c1303c17f2b/height=288;version=1;width=512/https%3A%2F%2Fblog.seesaa.jp%2Fimg%2Fogp_logo.png)