You should never use for/in for iterating an array. And, when you were doing so, you were just getting the array indices, not the actual array elements.
for/in iterates all enumerable properties of the object, not just array elements which can end up including things you do not want. See for ... in loop with string array outputs indices and For loop for HTMLCollection elements for details.
Instead, you can use any number of other options. The modern way is probably for/of which works for any iterable (which includes an array).
for/of
let array = [1, 2, 3];
for (let a of array) {
console.log(a);
}
.forEach()
let array = [1, 2, 3];
array.forEach(function(a, index) {
console.log(a);
});
Plain for loop
let array = [1, 2, 3];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
console.log(array[a]).ais the increment. I don't recommend using a for in loop on an Array though. Usearray.forEach(function(value, increment){}), or just a regularforloop if you want to break out of it, for faster execution. In theforEachloopvaluewill have your value without needing array[increment].inwithof.inis for iterating over keys of an object,ofis for iterating over values of an interable.