Standard built-ins

Array.prototype.forEach()

Try the free JavaScript compiler

Invokes a callback for present indices in ascending order and ignores its return values. Ordinary holes are skipped. No normal early break and no waiting for returned promises; use a loop for those needs.

Formal Syntax & Structure

javascript syntaxjavascript
array.forEach(callback, thisArg?)

Parameters & Attributes

NameTypeDescription
callbackfunctionPerforms an action with value, index and source.
thisArganyOptional this value for ordinary callback functions.

Return Value

undefined

Always undefined on normal completion.

Working Example

Example Snippetjavascript
const r=[2,4].forEach(x=>console.log(x)); console.log(r);
JavaScript Reference