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 @   大一脚步  阅读(261)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示