The expression to return. If omitted, undefined is returned instead.
Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.
由于 undefined
的计算结果为 false
,为什么下面会跳过迭代?
$.each([1,2,3], function(k, v){
if(v > 1)
return;
console.log(v); //1
});
最佳答案
没有跳过任何迭代。仅当该值大于 1
时才输出该值。 2
和 3
都大于 1
,因此不会记录它们的值,因此您在数组中看不到这些值的输出。
关于jquery - 为什么 "return;"会跳过 $.each() 中的迭代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140604/