Javascript - forEach


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.

Powered by ComboStrap