3

If I have arrays [A,B,C]and [1,2,3] How can I combine them to be [A,1,B,2,C,3]

aled
  • 21,330
  • 3
  • 27
  • 34
anonMule
  • 91
  • 2

2 Answers2

4

Assuming both arrays have the same length:

%dw 2.0
output application/json
var a1=["A","B","C"]
var a2=[1,2,3]
---
a1 flatMap [$, a2[$$]]

Output:

[
  "A",
  1,
  "B",
  2,
  "C",
  3
]
aled
  • 21,330
  • 3
  • 27
  • 34
2

You can also use zip

DW

%dw 2.0
output application/json
var a1=["A","B","C"]
var a2=[1,2,3]
---
flatten(a1 zip a2)

Output

[
  "A",
  1,
  "B",
  2,
  "C",
  3
]
Karthik
  • 2,181
  • 4
  • 10
  • 28