forEach()

Invoke a Function for each Array element.

Signature

forEach(function: (val: Any) => Any): Null

Description

The forEach() method sequentially calls function for each Array element, passing the element value as an argument to function.

the calling array isn’t changed.

Parameters

Parameter Type Required Description

function

Function

Yes

Function to invoke for each Array element in the calling Array. Each Array element is passed to function as an argument.

function parameters:

Parameter Type Required Description

val

Any

Current array element.

Return value

Type Description

Null

The return value of function is discarded.

Examples

Multiply each Array element by two:

[1, 2, 3, 4, 5].forEach((x) => {x * 2})
null

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!