V7016. Suspicious access to a collection element by a constant index inside a loop.
The analyzer has detected that the code accesses the same collection element on every iteration of a for loop using a constant index.
The example:
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[0]; // <=
}
In this case, it is intended to sum all elements of the array, but the index contains a typo. As a result, only the first array element is used, and the values of the other elements are ignored.
The fixed code:
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}