I was playing a bit with javascript and found out (at least for me) strange behaviour when dealing with multi-dimensional arrays via a foreach loop. So I have this piece of code
There were some good point from Erick Mickelsen pointed out but so sum it up.
for (... in ...) loop iterates over object propertiesarray IS an object in Javascript so you may iterate over an array with it. But it will be slower and it is generaly not recommended (see why is that)for (... in ...) loopas follows:
var third = '';
for (var arrayIndex in arr) {
third += ' ' + arr[arrayIndex][0] + ' ' + arr[arrayIndex][1];
}
In the associative array example the for (... in ...) loop will be handy:
var person = [];
person["id"] = 1;
person["born"] = 2009;
person["favourite_meal"] = "chicken";
var fourth = '';
for (var arrayIndex in person) {
fourth += ' ' + person[arrayIndex];
}