Array.prototype.forEach()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The forEach() method of Array instances executes a provided function once
for each array element.
Try it
const array = ["a", "b", "c"];
array.forEach((element) => console.log(element));
// Expected output: "a"
// Expected output: "b"
// Expected output: "c"
Syntax
js
forEach(callbackFn)
forEach(callbackFn, thisArg)
Parameters
callbackFn-
A function to execute for each element in the array. Its return value is discarded. The function is called with the following arguments:
thisArgOptional-
A value to use as
thiswhen executingcallbackFn. See iterative methods.