array.forEach

Using this function, you can iterate over a source array and filter the array elements based on a condition. If you do not provide any arguments, you can also create a single-item array.

Important: See the Mapping Complex Arrays for a detailed explanation of using the array.forEach() function.

Syntax

array.forEach(items, scopeName, filter)

Arguments

If you do not provide any arguments, you can create a single-item array.

Argument

Type

Description

items

array

Source array to iterate over.

scopeName

 

Scope for your mapping. Each scope has a name to it. By default, the scope name is the same as the name of the source array.

To use data:

  • To use parent data in the child array mappings, provide a scope name as a second argument in the corresponding parent array.forEach mapping and then use $loop[PARENT_SCOPE_NAME].<DATA_ATTRIBUTE> to access the corresponding data.
  • To use data from the current array, use $loop.<DATA_ATTRIBUTE>.

filter

 

Condition to filter the array elements. To use a filter, provide a scope name as the second argument and a boolean condition as a third argument.

In the filter condition, you can use data from: 

  • The parent array using the scope variable (for example, $loop[PARENT_SCOPE_NAME].<DATA_ATTRIBUTE>).
  • The current array (for example $loop.<DATA_ATTRIBUTE>).

Returns

Type

Description

array

The output array with filtered elements

Examples

  • array.forEach($flow.parameters.headers) returns array
  • array.forEach() returns array
  • array.forEach($flow.parameters.headers, "headerScope") returns array
  • array.forEach($flow.parameters.headers, "headerScope", $loop.Accept == "application/json") returns array