jq each和forEach的使用区别

首先看实例

var  arr=[["1","4"],["2"],["3","5","6"]];
var res=[];

//法一:使用forEach
arr.forEach(function(child,index){
    if(child.length>1){
        res.push(index);
    }
})


//法二:使用each
$.each(arr,function(index,child){
    if(child.length>1){
        res.push(index);
    }
})

需要注意:

1.forEach的调用者是对象,each是$

2.forEach两个参数分别表示子元素和系数。而each正好相反

记录编程的点滴,体会学习的乐趣
原文地址:https://www.cnblogs.com/AduBlog/p/15424840.html