I'm writing a simple code to get the value inside an array. I'm using array[key]
to get the value stored inside this array, in a for
loop.
var array = ["Foo", "Bar"];
function getValue() {
for (var key = 0; key < array.length; key++) {
console.log(array[value]);
}
}
This method is simple and works fine, however, I've read that this could cause security issue (The Dangers of Square Bracket Notation), and ESlint is not OK with it, throwing this error:
Generic Object Injection Sink (security/detect-object-injection)
Detects variable[key] as a left- or right-hand assignment operand. (ESLint reference)
How can I access the value of the array without using this method ?
I've already read the related question: Why is it bad pratice calling an array index with a variable? and as this question seems too hard to generalize I decided to ask a new canonical question.