---
schema_version: "1"
id: 85fc26d669aaa8553dfeb26b786cc09b62fb1d2a8d87b9b04db7660443bfc139
title: map
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-core-functions-map.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-core-functions-map
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 61b28b4397792e6705b8f593ec4641a2b3aae118337874042c17479aad535776
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# map

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## map(Array<T>, (item: T, index: Number) -> R): Array<R>

Iterates over items in an array and outputs the results into a new array.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>items</code></p></td><td><p>The array to map.</p></td></tr><tr><td><p><code>mapper</code></p></td><td><p>Expression or selector used to act on each <code>item</code> and optionally, each <code>index</code> of that item.</p></td></tr></tbody></table>

### Example

This example iterates over an input array (`["jose", "pedro", "mateo"]`) to produce an array of
DataWeave objects. The anonymous function `(value, index) → {index: value}` maps each item in the
input to an object. As `{index: value}` shows, each index from the input array becomes a key for an
output object, and each value of the input array becomes the value of that object.

#### Source

```DataWeave
%dw 2.0
output application/json
---
["jose", "pedro", "mateo"] map (value, index) -> { (index) : value}
```

#### Output

```JSON
[ { "0": "jose" }, { "1": "pedro" }, { "2": "mateo" } ]
```

### Example

This example iterates over the input array (`['a', 'b', 'c']`) using an anonymous function that acts
on the items and indices of the input. For each item in the input array, it concatenates the
`index + 1` (`index` plus 1) with an underscore (`_`), and the corresponding `value` to return the
array, `[ "1_a", "2_b", "3_c" ]`.

#### Source

```DataWeave
%dw 2.0
output application/json
---
['a', 'b', 'c'] map ((value, index) -> (index + 1) ++ '_' ++ value)
```

#### Output

```JSON
[ "1_a", "2_b", "3_c" ]
```

### Example

If the parameters of the `mapper` function are not named, the index can be referenced with `$$`, and
the value with `$`. This example iterates over each item in the input array
`['joe', 'pete', 'matt']` and returns an array of objects where the index is selected as the key.
The value of each item in the array is selected as the value of the returned object. Note that the
quotes around `$$` are necessary to convert the numeric keys to strings.

#### Source

```DataWeave
%dw 2.0
output application/json
---
['joe', 'pete', 'matt'] map ( "$$" : $)
```

#### Output

```JSON
[
  { "0": "joe" },
  { "1": "pete" },
  { "2": "matt" }
]
```

### Example

This example iterates over a list of objects and transform the values into CSV. Each of these
objects represent a CSV row. The `map` operation generates an object with `age` and `address` for
each entry in the list. `$` represents the implicit variable under iteration.

#### Source

```DataWeave
%dw 2.0
output application/csv
---
[{
  "age": 14 ,
  "name": "Claire"
}, {
  "age": 56,
  "name": "Max"
}, {
  "age": 89,
  "name": "John"
}] map {
    age: $.age,
    name: $.name
}
```

#### Output

```CSV
age,name
14,Claire
56,Max
89,John
```

## map(Null, (item: Nothing, index: Nothing) -> Any): Null

Helper function that enables `map` to work with a `null` value.
