I have this rows code:
_.each($scope.inspectionReviews, function (value, key) {
alert("status=" + value.IsNormal + " " + "name=" + value.InspectionItemName);
if (!value.IsNormal) {
$scope.status = false;
return;
}
$scope.status = true;
})
At some point I want to stop looping but it seems that return not working.
How can I stop the loop?
Javascript. Conclusion: Hence to break Lodash forEach loop we have to return false from the callback function.
Lodash is one of those handful of libraries, that were created to solve a growing problem, that fortunately due to Microsoft's foresight, no longer exists.
Summary. Lodash is a JavaScript library that helps programmers write more concise and maintainable JavaScript. It can be broken down into several main areas: Utilities - for simplifying common programming tasks such as determining type as well as simplifying math operations.
Lodash is extremely well-optimized as far as modern JS goes, but, as you may know, nothing can be faster than native implementation. Even if Lodash uses the same API under-the-hood, function call overhead is still present. Some might say that these are just some micro-optimizations.
return false;
Use this in a lodash each
to break.
EDIT: I have seen the title changed to underscore. Is it underscore or lodash? As I pointed out above you can break an each
in lodash but underscore I believe emulates forEach
which natively doesn't provide that.
return false => it has exactly the same effect as using break;
return => this is the same as using continue;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With