您的位置:首页 > Web前端 > JQuery

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

2017-08-23 14:33 423 查看
 

[问]


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

jquery.Each() documentation

Returning non-false is the same as a continue statement in a for loop, it will skip immediately to the next iteration.

I've tried calling 'return non-false;' and 'non-false;' (sans return) neither of which skip to the next iteration. Instead, they break the loop. What am i missing?

【答】

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;

}

alert(arr[i]);

});

Will alert one, two, four, five

 

From: https://stackoverflow.com/questions/481601/how-to-skip-to-next-iteration-in-jquery-each-util
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: