I am converting some existing code to follow an ECMA script, and I am using ESLint to follow the coding standard. I have the following ecacccript method
static getArrayOfIndices(text, char) { let resultArray = []; let index = text.indexOf(char); const lastIndex = text.lastIndexOf(char); while (index <= lastIndex && index !== -1) { resultArray.push(index); if (index < lastIndex) { index = text.substr(index + 1).indexOf(char) + index + 1; } else { index = lastIndex + 1999; // some random addition to fail test condition on next iteration } } return resultArray; }
ESLint throws error for resultArray declaration
ESLint: `resultArray` is never modified, use `const`instead. (prefer-const)
But since elements are inserted into an array, doesn't that change?
source share