forEach()

 var arr = [6,2,5,4,2];
     arr.forEach(function(correntvalue,index,array){
        //  console.log(correntvalue);   //correntvalue是当前项
        //  console.log(index); //index是当前项的索引
        //  console.log(array); //array是调用forEach的数组
    })

forEach是ES5新增的方法,有三个返回值

第一个返回值是当前项    correntvalue

console.log(correntvalue)

 

第二个返回值是当前项的索引    index

console.log(index)

 

第三个返回值是调用forEach的数组  array

console.log(array)

 


posted @ 2019-07-23 20:45  前端小菜鸟吖  阅读(4668)  评论(0编辑  收藏  举报