Using underscore.js is there a way to breakout of the each if a certain condition is met?
_.each([1,2,3], function(value) {
if (value == 2) {
// continue 2
return false;
}
});
I’m sure returning false did the trick in prototype.js
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Looks like you should return
breaker, which isn’t in scope it seems. So, without modifying_, you can’t easily break out of iteration. The===there will ensure that returning{}won’t cause the loop to break; you need a reference tobreaker, which you don’t have.