Iterating an array collection in Javascript

MiNdAr

New Member
I'm having trouble with iterating and getting the values within a collection of arrays (an array of arrays I guess)I'd hope that the code below would display an alert showing the 3 values of each array in turn (eg "infant", "0" and then "2") but the alert just displays "0" "undefined", undefined".What am I missing?Declare the array:\[code\]var ageGroups = [["infant", 0, 2], ["child", 3, 18], ["child", 3, 17], ["adult1", 18, 64], ["adult2", 65, 74], ["adult3", 75, 79]];\[/code\]Iterate the array\[code\]for (var item in ageGroups) { alert(item[0]); alert(item[1]); alert(item[2]);}\[/code\]
 
Top