This is the method I tried to run:
function SayHello() {
cars = new Array();
cars[0] = "Toyota";
cars[1] = "Mitsubishi";
cars[2] = "Honda";
for (car in cars) {
alert(car);
}
}
This returns:
0
1
2
When I changed the code to this:
function SayHello() {
cars = new Array();
cars[0] = "Toyota";
cars[1] = "Mitsubishi";
cars[2] = "Honda";
for (car in cars) {
alert(cars[car]);
}
}
He correctly returned the names.
My question is, does the for-in loop just return the index in an ordered manner? Thank.
delete
source
share