---
category: [Administration & Integrations, Platform and Product Extensions, Platform and Product Extensions/Integration, Administration & Integrations/Custom Integrations & Apps, Platform and Product Extensions/Workday Extend]
keyword: [Extend, PMD Scripting, Scripts]
nav: wcp_docs
parent_url: /wcp_docs/
title: forEach (closure)
layout: subsection
---

## <a id="section_m3p_myb_5db"></a>Description

Calls the specified function on each map element until the action has processed all or the action throws an exception.

## <a id="section_cyq_j1m_zsb"></a>Return Type

`void`

## <a id="section_dz5_pwg_5db"></a>Instance Method Syntax

```
thisMap.forEach(closure)
```

<table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td>closure</td><td>The BiFunction (with 2 parameters) called for each map element. <p>Within a closure, you can't redefine the variables that are declared outside the closure.</p></td></tr></tbody></table><br/>

<b>Example</b>

`var keys = []; {'foo': 1, 'bar': 2}.forEach((k, v) => {keys.add(k)})`

Result: `keys = [bar,foo]`

## <a id="section_njs_xzl_zsb"></a>Namespace Function Syntax

```
map:forEach(map, closure)
```

<table><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td>map</td><td>The input Map.</td></tr><tr><td>closure</td><td>The BiFunction (with 2 parameters) called for each map element.</td></tr></tbody></table><br/>

