Convert Loop to For...Of

Replace regular for loops with for...of loops.

refactoring (convert)
ES2015 modernization
safe

for...of loops over iterable objects, for example arrays or strings.

It is easier to read than indexed for loops and can replace them in many cases.

Refactoring Example

Before:

for (let i = 0; i < elements.length; i++) {
  const element = elements[i];
  console.log(element);
}

After:

for (const element of elements) {
  console.log(element);
}

Related Code Actions