JavaScript forEach Array method

Quick Usage

For this quick usage consider that var awesomeArray = [1, 2, 3, 4, 5];.awesomeArray.forEach(function(element, index) { });


Javascript’s ES5 forEach() Array method is a fast way to iterate through all elements of an array. It executes the provided function for each element of the array, passing down the current element and index.

  • Full syntax example

    var awesomeArray = [1, 2, 3, 4, 5];
    var thisValue = window;

    awesomeArray.forEach(function(element, index, array) {
    /* do something */
    }, thisValue);

  • Paramenters

    • function(element, index, array)

      Function passing the current elementcurrent index and the full arrayas paramenters.

    • thisValue

      The context on which the function is running. Defaults to undefined.

  • Return Value

    This method returns undefined.

  • Support

    All browsers.