useForOf
诊断类别:lint/style/useForOf
¥Diagnostic Category: lint/style/useForOf
自从:v1.5.0
来源:
¥Since: v1.5.0
Sources:
-
与以下相同:
@typescript-eslint/prefer-for-of
¥Same as:
@typescript-eslint/prefer-for-of
-
与以下相同:
unicorn/no-for-loop
¥Same as:
unicorn/no-for-loop
此规则建议在 for
循环中使用 for-of
循环,索引用于从迭代数组中提取项目。
¥This rule recommends a for-of
loop when in a for
loop, the index used to extract an item from the iterated array.
¥Examples
¥Invalid
code-block.js:1:1 lint/style/useForOf ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Use for-of loop instead of a for loop.
> 1 │ for (let i = 0; i < array.length; i++) {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ console.log(array[i]);
> 3 │ }
│ ^
4 │
¥Valid
¥Related links