28 Feb 2010
Javascript
Foreach
Javascript lets you have associative arrays (of sorts), e.g:
var myArray = {
a : 'val1',
b : 'val2'
};
If you want to loop over this array, you can use a foreach loop:
for( x in myArray ) {
alert(myArray[x]);
}
This code will pop up a message box for each entry in the array. Because the key is assigned to the variable x, you can use the key as well as the value.