for (var name in ['dog','cat','cow']) {
alert(name);
}
The name here is returning the index of the array, but I can’t refer to it since it’s anonymous.
I know I can declare it outside the loop, but here I’m asking if is there a way for refering to the name directly that is without index.
If you know the keys of the array are going to be integers, there’s nothing that necessitates the use the
for..inconstruct.In the above code, a simpler
forloop allows for the creation of a new object and referencing by key inside the loop.