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

# zip

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

## zip<T, R>(left: Array<T>, right: Array<R>): Array<Array<T | R>>

Merges elements from two arrays into an array of arrays.

The first sub-array in the output array contains the first indices of the input sub-arrays. The
second index contains the second indices of the inputs, the third contains the third indices, and so
on for every case where there are the same number of indices in the arrays.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>left</code></p></td><td><p>The array on the left-hand side of the function.</p></td></tr><tr><td><p><code>right</code></p></td><td><p>The array on the right-hand side of the function.</p></td></tr></tbody></table>

### Example

This example zips the arrays located to the left and right of `zip`. Notice that it returns an array
of arrays where the first index, (`[0,1]`) contains the first indices of the specified arrays. The
second index of the output array (`[1,"b"]`) contains the second indices of the specified arrays.

#### Source

```DataWeave
%dw 2.0
output application/json
---
[0,1] zip ["a","b"]
```

#### Output

```JSON
[ [0,"a"], [1,"b"] ]
```

### Example

This example zips elements of the left-hand and right-hand arrays. Notice that only elements with
counterparts at the same index are returned in the array.

#### Source

```DataWeave
%dw 2.0
output application/json
---
{
  "a" : [0, 1, 2, 3] zip ["a", "b", "c", "d"],
  "b" : [0, 1, 2, 3] zip ["a"],
  "c" : [0, 1, 2, 3] zip ["a", "b"],
  "d" : [0, 1, 2] zip ["a", "b", "c", "d"]
}
```

#### Output

```JSON
{
  "a": [
    [0,"a"],
    [1,"b"],
    [2,"c"],
    [3,"d"]
    ],
  "b": [
    [0,"a"]
  ],
  "c": [
    [0,"a"],
    [1,"b"]
  ],
  "d": [
    [0,"a"],
    [1,"b"],
    [2,"c"]
  ]
}
```

### Example

This example zips more than two arrays. Notice that items from `["aA", "bB"]` in `list4` are not in
the output because the other input arrays only have two indices.

#### Source

```DataWeave
%dw 2.0
output application/json
var myvar = {
   "list1": ["a", "b"],
   "list2": [1, 2, 3],
   "list3": ["aa", "bb"],
   "list4": [["A", "B", "C"], [11, 12], ["aA", "bB"]]
}
---
((myvar.list1 zip myvar.list2) zip myvar.list3) zip myvar.list4
```

#### Output

```JSON
[
  [
    [ [ "a", 1 ], "aa" ], [ "A", "B", "C" ]
  ],
  [
    [ [ "b", 2 ], "bb" ], [ 11, 12 ]
  ]
]
```
