each方法
jquery的方法,不能使用break打斷循環,return falsed代表for循環中的break
obj.each(function (i,item) {
// i:循環的下標
// item:循環的節點
// $(this):jquery對象
// $(item):獲得要循環的div的單個jquery對象
})
$.each(obj,function (i,item) {
// i:下標
// item:循環的節點對象
// $(this):jquery對象
// $(item):獲得要循環的div的單個jquery對象
})
forEach方法
只能遍歷數組,不能使用break打斷循環,return falsed代表for循環中的continue
arr.forEach(function (i,item) {
//arr:循環遍歷的數組
// item:數組每一項得值
// i:每一項對應的下標
})
for循環
常用於數組的循環遍歷 for(let i=0;i<arr.length;i++){ //arr:循環遍歷的數組 //arr[i]:數組中該下標的值 }