Javascript - foreach instruction


forEach is a terminal javascript functional operation that will loop over each element:


The syntax is important, the function is called forEach with a uppercase E, otherwise you get a Unknown function call


['blue', 'green', 'yellow'].forEach((color, index) => console.log(`${index} - ${color}`));

Functional Programming

With map

    .map(letter => letter.toUpperCase())
    .forEach(letter => console.log(letter));

Return and not continue

In a foreach loop, you should use the return function to stop the processing and not continue.

Discover More
DOM - Child Nodes of a Node

Child Nodes of an element in the dom tree Via child selector, you can select element that are child of another element. The childNodes property of an element returns a collection of child Node....
DOM - Collection Iteration (NodeList, ..)

in the DOM. API A selection of element with the Web API DOM is returned as a nodelist. For forEach Property Web API Example Source...
DOM - NodeList (Collection)

A nodelist is the result of a selection that returns more than one node (Generally an element) Nodelist: HTMLAllCollection, HTMLFormControlsCollection, HTMLOptionsCollection, interfaces are...
Javascript - (Loop|Iterator)

This page is how to iterate in Javascript (ie the Iterator pattern in Javascript) To iterate / loop in Javascript, you can use the following syntax structure: the for statement the functional...
Functional Programming in Javascript

Functional Programming in Javascript in javascript. array operationsDoc To get the cookies All function...
Javascript - Map function (Functional programming)

The functional programming function map in a Javascript context is only an array method as all functional programming javascript method. map With an Arrow function as argument Letters that we...
Javascript - Object

object in javascript An object is a data type in Javascript. An object follows a json data structure with key that holds property value. The value may be of a variable or a function In JavaScript, a...

Share this page:
Follow us:
Task Runner