天天看點

for of 如何周遊下标

keys 周遊每一項的接口,使用for of 周遊

/*
    * keys 周遊每一項的接口,使用for of 周遊
    *
    * */
    let aryKeys = [1,2,3,4,5];
    for(let item of aryKeys.keys()){
        console.log('可以周遊for of的下标', item);
    }
      

可以周遊for of的下标 0

可以周遊for of的下标 1

可以周遊for of的下标 2

可以周遊for of的下标 3

可以周遊for of的下标 4

2entries 周遊接口,可以周遊到索引的每一項,每一次周遊得到一個數組【索引,目前項】

/*
    * entries 周遊接口,可以周遊到索引的每一項,每一次周遊得到一個數組【索引,目前項】
    *
    * */
    for(let e of aryKeys.entries()){
        console.log('entries【索引,目前項】',e);
    }      

3

//預設使用for of 周遊數組,預設周遊的就是每一個項
    for(let it of aryKeys){
        console.log('for of每一個項',it);
    }