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. How can the index of the array the that i
is currently on be accessed.
What I want
let array = ["one", "two", "three"];
for (let i of array) {
console.log(i);// normally logs cycle one : "one", cycle two : "two", cycle three : "three".
console.log(/*what equals the current index*/);// what I want to log cycle one : 1, cycle two : 2, cycle three : 3.
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…