jquery - 为什么 "return;"会跳过 $.each() 中的迭代?

标签 jquery

MDN on the return statement:

The expression to return. If omitted, undefined is returned instead.

jQuery docs on $.each :

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
});

Fiddle

最佳答案

没有跳过任何迭代。仅当该值大于 1 时才输出该值。 23 都大于 1,因此不会记录它们的值,因此您在数组中看不到这些值的输出。

关于jquery - 为什么 "return;"会跳过 $.each() 中的迭代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140604/

相关文章:

php - 如何以循环顺序显示数据库中的报价?

javascript - Jasmine:使用可变 URL stub ajax 请求

javascript - 我有 9 个小图像,单击这些图像时,它们会在较大版本的图像中淡出。为什么在浏览器中不起作用(FF))

javascript - jQuery 拖动/调整大小与 CSS 变换比例

jquery - 在 div 中动态添加 <span> 将每个 span 标签设置为相等的高度

javascript - 从服务器生成客户端 JavaScript 时主要关注什么?

javascript - 如何使用 jquery 在某个点滚动页面本身?

jquery - Fluid 960 Grid jQuery slideToggle

javascript - 使用 getScript 异步加载脚本

javascript - 如何使用jquery将鼠标悬停在url地址栏上时禁用光标