Reputation: 57
I have a code where I need to change a for/of loop into a normal for loop, but I don't know how to convert the variables. Such as if a have a
for (let sentence of sentences)
How do I change it to this structure?
for (var i = 0; i < .length; i++)
Upvotes: 1
Views: 619
Reputation: 1386
You can do this
for (let i = 0; i < sentences.length; i++) {
console.log(sentences[i]); // it's your current sentence
}
UPD
How correctly noticed @FZs my code won't work on different types of iterables.
For transform iterator to array you can use Array.from
method. I put link to MDN here
Upvotes: 2