Nav

unzip

unzip(Array<Array<T>>): Array<Array<T>>

Performs the opposite function of //* [zip arrays]. That is, given a single array where each index contains an array with two elements, it outputs two separate arrays, each with the corresponding elements of each pair.

This can also be scaled up: If the indexes in the provided array contain arrays with more than two elements, the output will contain as many arrays as there are elements for each index.

Transform

        
     
1
2
3
4
5
6
7
8
%dw 2.0
output application/json
---
{
  a: unzip([[0,"a"],[1,"b"],[2,"c"],[3,"d"]]),
  b: unzip([ [0,"a"], [1,"a"], [2,"a"], [3,"a"]]),
  c: unzip([ [0,"a"], [1,"a","foo"], [2], [3,"a"]])
}
Output

        
     
1
2
3
4
5
6
7
8
9
10
11
12
13
{
   "a":[
      [0, 1, 2, 3],
      ["a", "b", "c", "d"]
    ],
  "b": [
      [0,1,2,3],
      ["a","a","a","a"]
    ],
  "c": [
      [0,1,2,3]
    ]
}

Note that even though example b can be considered the inverse function of example b in //* [zip array], the result is not analogous because it returns an array of repeated elements instead of a single element. Also note that in example c, the number of elements in each component of the original array is not consistent. So the output only creates as many full arrays as it can, in this case just one.