[問題] jQuery each

作者: Telete (艾小可)   2017-05-28 00:34:19
// ARRAYS
var arr = [
'one',
'two',
'three',
'four',
'five'
];
$.each(arr, function (index, value) {
console.log(value);
// Will stop running after "three"
return (value !== 'three');
});
// Outputs: one two three
因為不懂jQuery 的 each方法所以去找了教學
看網路上的範例是這樣寫的
想請教的是,最後面的outputs
為何是 one two three
return (value !== 'three');
這是表示,假如值不是three的話就中止吧
那 one two 也不是 three啊
不是應該一開始就中止嗎??
還請各位高人們解惑~~謝謝
作者: Kenqr (function(){})()   2017-05-28 00:48:00
return false時會中止,value是'three'的時候才會是false
作者: pm2001 (做個盾牌眼球兵吧)   2017-05-28 01:06:00
關鍵字 jquery each continue break
作者: LPH66 (-6.2598534e+18f)   2017-05-28 06:20:00
重點是一樓的「return false 時會中止」換句話說「return 條件是繼續的條件」, 跟 while 一樣也就是說概念上這等於是一個 do-while 迴圈
作者: steven11329 (清新柳橙)   2017-05-28 22:07:00
Will stop running after "three"翻中文是three之後才停止他沒有寫錯,是你英文理解錯誤。

Links booklink

Contact Us: admin [ a t ] ucptt.com