How to skip to next iteration in jQuery.each() util?

后端 未结 6 741
栀梦
栀梦 2020-12-07 07:39

I\'m trying to iterate through an array of elements. jQuery\'s documentation says:

jquery.Each() documentation

Returning non-false is the same

6条回答
  •  感动是毒
    2020-12-07 08:00

    Dont forget that you can sometimes just fall off the end of the block to get to the next iteration:

    $(".row").each( function() {
        if ( ! leaveTheLoop ) {
            ... do stuff here ...
        }
    });
    

    Rather than actually returning like this:

    $(".row").each( function() {
        if ( leaveTheLoop ) 
            return; //go to next iteration in .each()
        ... do stuff here ...
    });
    

提交回复
热议问题