Array.prototype.forEach

Calls the given function for each element of an array.

Syntax

forEach(callback, thisArg?)

Parameters

Remarks

forEach is useful for performing side-effects with array elements. To transform each array element, consider map.

Examples

[23, 42, 108].forEach(x => print(x))
23
42
108

let drinks = ["coffee", "tea", "juice"]

function itemize(item, index) {
  print(`${index}. ${item}`)
}

drinks.forEach(itemize)
0. coffee
1. tea
2. juice