For Each Loop Over An Array In JavaScript

For More Videos Visit Our YouTube Channel

Here we consider how to loop through all members in an array using JavaScript. Lets start with one example here. Suppose we have an array as shown here in javascript. For looping through all elements in javascript, we can make use of foreach or for loop.

var array = ["1", "2", "3"];
array.forEach( function( object ) {
         alert( object );

var array = ["1", "2", "3"];
for (var index = 0; index < array.length; ++index) {
     alert( array[index] );