Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break -.each() loop #960

Closed
maheshhfs opened this issue Jan 31, 2013 · 1 comment
Closed

Break -.each() loop #960

maheshhfs opened this issue Jan 31, 2013 · 1 comment

Comments

@maheshhfs
Copy link

Hi, I need to break loop after my if(condition) is true without throwing exception.
What i do......

eg:

_.each(MyArray,function(element){
// My work done on element....
if(condition) {
break; // Any idea to break the outer -.each() loop.
}
});

Really i need to break loop showing in eg.
Thanks in advance.

.........Mahesh

@caseywebdev
Copy link
Contributor

You can't do it with _.each, but you can do it with _.any...

_.any(MyArray, function (element) {
  if (condition) return true; // break
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants