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);

 

posted @ 2017-09-07 08:15  大一脚步  阅读(260)  评论(0编辑  收藏  举报