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

后端 未结 6 713
栀梦
栀梦 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 07:57

    What they mean by non-false is:

    return true;
    

    So this code:

    var arr = ["one", "two", "three", "four", "five"];
    $.each(arr, function(i) {
      if (arr[i] == 'three') {
        return true;
      }
      console.log(arr[i]);
    });

    will log one, two, four, five.

提交回复
热议问题