Iterating Through Arrays

You can iterate through an array by using a for or a for/in loop. The following code illustrates iterating through each item in the array using each method:

var week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"];for (var i=0; i<week.length; i++){  console.log("<li>" + week[i] + "</li>");}for (dayIndex in week){  console.log("<li>" + week[dayIndex] + "</li>");}

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.