How to stop lodash.js _.each loop?

Michael picture Michael · Oct 21, 2015 · Viewed 51k times · Source

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?

Answer

AtheistP3ace picture AtheistP3ace · Oct 21, 2015
return false;

Use this in a lodash each to break.

EDIT: I have seen 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.