length property should not be omitted for the array in a loop condition

  • Error
  • Medium
  • No tags

This rule applies when the length property is missing in the loop condition expression.

When an index variable is used to iterate through array elements, it is necessary to compare it with the length property of the array in the loop condition.

If the length property is omitted by mistake, the array itself is compared and the loop will not be executed at all.

Noncompliant Code Example

View with compliant examples side by side
for (var i = 0; i < array; i++) { // MISSING_LENGTH_IN_LOOP_CONDITION alarm
    array[i] = i;

Compliant Code Example

View with noncompliant examples side by side
for (var i = 0; i < array.length; i++) {
    array[i] = i;


This rule was introduced in DeepScan 1.19.0.


Was this documentation helpful?