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.