no-explicit-array-loops
Disallows explicit iteration for arrays.
In this case, "explicit iteration" means using the values
method (or Object.values
) in a for loop. Forbidding this can make code easier to read.
Also see the no-explicit-map-set-loops
rule.
Rule Details
In JavaScript/TypeScript, you can iterate over array elements implicitly:
for (const element of myArray) {
}
Or, you can iterate over array elements explicitly:
for (const element of myArray.values()) {
}
Idiomatic TypeScript code iterates implicitly. Explicit iteration is rare because it is needlessly verbose. Thus, it is recommended to forbid this pattern in your codebase to prevent confusion and ensure consistency.
Options and Defaults
{
"rules": {
"complete/no-explicit-array-loops": "error"
}
}
This rule is not configurable.