Tuesday, April 20, 2010

Javascript foreach equivalent

Javascript foreach equivalent



Javascript has no foreach statement. Instead, we use the following syntax.


var letters = ["a","b","c"];

for(var i in letter) {
alert(letters[i]);
}


Note the variable i, is an index into the array, and not a reference to the array element.

No comments:

Post a Comment