1

Does Dataweave 2.0 has for loop? For example I have the following code

%dw 2.0
var value = 0
var myArray=[1,2,3,4,5]
output application/json
---
{
    value : myArray[3]
}

the variable value will have a value of 4 in this case. Is it possible to have some kind of for-each loop and go through the whole array?

borna
  • 906
  • 3
  • 12
  • 32
  • 1
    Yes you can, but by wrapping data weave in for each, execute it to loop through values. Send values as Arrays, set logger inside for each and check for each array. – Ven Jul 18 '19 at 13:47

1 Answers1

1

The answer is no. DataWeave follows a functional programming paradigm. For each is an imperative construct, not compatible with functional programming.

You can other methods to achieve the desired result like using map(). For an explanation look at the documentation page: https://docs.mulesoft.com/mule-runtime/4.1/dataweave-cookbook-map

aled
  • 21,330
  • 3
  • 27
  • 34