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)