Convert loop to for…of
Replace regular for
loops and anArray.forEach
loops with for…of
loops.

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);
}
Configuration
- Code Assist ID (for the configuration file):
convert-loop-to-for-of
- You can configure custom keyboard shortcuts with this code action kind:
refactor.convert.p42.convert-loop-to-for-of
- This code assist provides refactoring suggestions. Learn how to configure the refactoring suggestion visibility.