For Loop Over An Array In JavaScript
> 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.
For Each Loop
var array = ["1", "2", "3"];
array.forEach( function( object ) {
alert( object );
});
For Loop
var array = ["1", "2", "3"];
for (var index = 0; index < array.length; ++index) {
alert( array[index] );
}
Watch Video of this Content on Video Streaming