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)

 

 
         
         
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM