在jQuery的`each();`方法中实现`continue;`关键字

Sae*_*ati 3 javascript jquery loops

想象一下,我想循环遍历一个jQuery对象列表,并为每个对象执行一些函数.但是,如果在某个地方,不符合标准,那么我只想要continue;其他对象.简单的伪代码可能是这样的:

$('#element').each(function(){
    // some code here
    if (!$(this).is('.included')) {
       continue; // This keyword of course, doesn't work here
    }
    // more code here, which won't get executed for some elements
});
Run Code Online (Sandbox Code Playgroud)

我想达到同样的效果:

for (var i = 0; i < 10; i++) {
    if (i % 2 == 0 ) {
        continue;
    }
    console.log(i);
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以在return false;某个each();方法内部,完全打破循环.但我不想打破循环.我只想跳过一些元素.我也知道我可以使用if-else块来跳过元素,但是有更简洁的方法吗?

Mol*_*Man 9

只需使用return;而不是continue;(不return false;).