Coffeescript: Break out of a forEach loop

Possible Duplicate:
Javascript Array.forEach HowTo break?

Given that I have a forEach loop, how do I break out of that loop in case X is true?

For example:

user.forEach (x,i) ->

                    if x.status == "available"
                        -- I want to break here - 

Thanks


Basically, don't. forEach is meant to be essentially "functional". You could break it with an exception, but exceptions should be used for "exceptional" conditions, not control flow.

If you mean to break, you don't mean a functional form, you mean an iteration. Use a for loop.

链接地址: http://www.djcxy.com/p/70046.html

上一篇: 在JavaScript中打破forEach方法的首选方法

下一篇: Coffeescript:分解forEach循环