foreach用法

//array.forEach(function(currentValue,index,arr),thisValue);

//currentValue,必需,当前元素
//index 可选,当前元素的索引值
//arr 可选,当前元素所属的数组对象
//thisValue 可选,传递给函数的值一般用this值,如果参数为空,undefined会传递给this
var num = [1,3,5,7]; var sum = 0; function myFunction(item,index){ sum+=item; } num.foreach(myFunction);
原文地址:https://www.cnblogs.com/yfafa/p/7487944.html