underscore.jsのeachを使っているとき、下記のようにしてもループは途中で終わりません。
_.each([1,2,3,4,5,6], function (elem) {
console.log(elem)
return false
})
出力
1
2
3
4
5
6
_.every
を使う
_.every([1,2,3,4,5,6], function (elem) {
console.log(elem)
return false
})
出力
1
Returns true if all of the values in the list pass the predicate truth test. Short-circuits and stops traversing the list if a false element is found.
デバッグなどでループを全部回したくない場合は_.every
を使うと便利かもしれません。
以上です。