December 2013
Intermediate to advanced
384 pages
9h 54m
English
var weekdays = ["Mon", "Tue", "Wed", "Thur", "Fri"]; for(var x=0; x < weekdays.length; x++){ document.write(day+"|"); } //Output is "Mon|Tue|Wed|Thur|Fri|"
The best method to iterate through JavaScript arrays is to use a for(init; condition; adjustment){LOOP_BLOCK} loop. The for() loop allows you to initialize a variable and then iterate through until a condition is met. To loop through the array, initialize an index and then stop the loop when the index is equal to the length of the array.
Read now
Unlock full access