目录

@typescript-eslint/no-for-in-array

Disallow iterating over an array with a for-in loop.

This rule applies only to .js and .ts files.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-for-in-array": "error"
  }
}

Options

This rule is not configurable.

Example of Correct Code

declare const array: string[];

for (const value of array) {
  console.log(value);
}

array.forEach((value) => {
  console.log(value);
});

Example of Incorrect Code

declare const array: string[];

for (const i in array) {
  console.log(array[i]);
}

for (const i in array) {
  console.log(i, array[i]);
}

Rule Set

plugin:@typescript-eslint/recommended
plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.