June 2014
Intermediate to advanced
696 pages
38h 52m
English
Another type of for loop is the for/in loop. The for/in loop executes on any data type that can be iterated. For the most part, you will use for/in loops on arrays and objects. The following example illustrates the syntax and behavior of the for/in loop on a simple array:
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];for (var idx in days){ console.log("It's " + days[idx] + "<br>");}
Notice that the variable idx is adjusted each iteration through the loop, from the beginning array index to the last. The resulting output is:
It's MondayIt's TuesdayIt's WednesdayIt's ThursdayIt's Friday
Read now
Unlock full access