Skip to main content

no-explicit-array-loops

💼 This rule is enabled in the ✅ recommended config.

Disallows explicit iteration for arrays.

🔧 This rule is automatically fixable by the --fix CLI option.

💭 This rule requires type information.

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​

This rule is not configurable.

Resources​