forEach是ES5中操作数组的一种方法,主要功能是遍历数组,例如:var arr = [1,2,3,5];arr.forEach(function(value,index,array){ console.log(“value是”+value); console.log(“index是”+index); console.log(“array是”+array);});等价于:var arr = [1, 2, 3, 4];for (var k = 0, length = arr.length; k < length; k++) { console.log(“value是”+arr[k]); console.log(“index是”+k);}forEach方法中的function回调有三个参数:第一个参数是遍历的数组内容,第二个参数是对应的数组索引,第三个参数是数组本身因此:[].forEach(function(value,index,array){ //code something });等价于:$.each([],function(index,value,array){ //code something })写一个例子:var arr = [1,2,3,4];arr.forEach(function(value,index,array){ array[index] == value; //结果为true sum+=value; });console.log(sum); //结果为 10map:map即是 “映射”的意思 用法与 forEach 相似,用法即:[].map(function(value,index,array){ //code })