Javascript - forEach

About

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

Example

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

Array

['blue', 'green', 'yellow'].forEach(color => console.log(color));

Functional Programming

With map

['a','b','c']
    .map(letter => letter.toUpperCase())
    .forEach(letter => console.log(letter));

Powered by ComboStrap