how to break out from outer each loop

后端 未结 2 453
我在风中等你
我在风中等你 2021-01-04 14:30

I have the following scenario:

$.each(array, function() {
    ...
    $.each(array1, function() {
        if condition () { }
    });
});

H

相关标签:
2条回答
  • 2021-01-04 14:53
    $.each(array, function() {
        var flag = true;
    
        $.each(array1, function() {
            if (condition) {
                flag = false;
                return false;
            }
        });
    
        return flag;
    });
    
    0 讨论(0)
  • 2021-01-04 14:58

    Set a value to test in the outer loop to exit

    $.each(array, function() {
        var exit = false;
        $.each(array1, function() {
            if ( condition ) { 
               exit = true;
               return false;
            }
        }
        if (exit){
            return false;
        }
    }
    
    0 讨论(0)
提交回复
热议问题