Looping with Array.forEach() Method

Published on: December 17, 2016

Welcome to the 26th Easy JavaScript tutorial, part of EasyProgramming.net. In this tutorial, we cover the forEach array method as we continue to learn about loops.

This is the last array method that I skipped when I did the Array Methods tutorial in tutorial 14 - feel free to check that out for more info!

The forEach method iterates through each array item and executes a block of code. It will complete when it has gone through every item in the array.

Let's take a look at the Syntax of the forEach method:

  array.forEach(function(item, index){
    execute code;
    the 'item' is the actual value;
    'index' is the index number (e.g. i);


To fork the fiddle and follow along: https://jsfiddle.net/easyjs/63svc12y/

Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!