Clarity on for loops that use name instead of 'i' counter

Could anyone please help me understand the following:

Looking at the example below, would I be correct in saying the value of keys a string and not a number?

Secondly, how should one refer to this type of for loop, i.e., the ‘counting’ mechanism?

let animalArray = ['aardvark', 'badger', 'civet', 'dik-dik'];
for ( keys in animalArray) {
    console.log('Position: ' + keys + '  Value:  ' + animalArray[keys]);

Yes they are strings

I guess you could call it iterating over all enumerable string properties, but I don’t think calling it a for…in loop is wrong

you should avoid using variables without let/const, it becomes a global variable and persists after the last iteration

Much appreciated - many thanks

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.