How can the current number of i be accessed in a for of loop?

前端 未结 6 1103
一个人的身影
一个人的身影 2020-12-03 20:54

Given a for of loop the value of the assigned the variable(i for this example) is equal to what array[i] would equal if it was a normal for loop. H

6条回答
  •  失恋的感觉
    2020-12-03 21:31

    Or

    array = ["one", "two", "three"];
    
    for (i = 0, item; item=array[i]; i++) {
      console.log(i); // Logs the current index number;
      console.log(item); // Logs the current item in the array;
    }
    

提交回复
热议问题