Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 753 Bytes

no-for-of.md

File metadata and controls

25 lines (17 loc) · 753 Bytes

Disallow usage of the for-of syntax (no-for-of)

The for-of syntax was introduced in ES6. On older browsers, this syntax is transpiled down to ES5. Since for-of is based upon the iterable protocol, the generated code is bloated and nonperformant. If your app supports older browsers, use a standard for instead.

Rule details

Example of incorrect code:

const arr = [1, 2, 3];

for (let item of arr) {
    console.log(item);
}

Example of correct code:

const arr = [1, 2, 3];

for (let i = 0; i < arr.length; i++) {
    console.log(i);
}