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>");
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.234