1

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++) 
0

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

so where does my sentence variabel go? i need it further done in my code
@KarlaJensen You can access sentence like sentences[i]
@FZs You're absolutely right and I updated my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.