If I have arrays [A,B,C]and [1,2,3]
How can I combine them to be [A,1,B,2,C,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]
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
]
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
]