Bazil
1
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]);
}:
tzerio
2
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
Bazil
3
Much appreciated - many thanks
system
Closed
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.