Contact Free trial Login


flatMap(Array<T>, (item: T, index: Number) -> Array<R>): Array<R>

Iterates over each item in an array and flattens the results.

Instead of returning an array of arrays (as map does when you iterate over the values within an input like [ [1,2], [3,4] ]), flatMap returns a flattened array that looks like this: [1, 2, 3, 4]. flatMap is similar to flatten, but flatten only acts on the values of the arrays, while flatMap can act on values and indices of items in the array.


Name Description


The array to map.


Expression or selector for an item and/or index in the array to flatten.


This example returns an array containing each value in order. Though it names the optional index parameter in its anonymous function (value, index) → value, it does not use index as a selector for the output, so it is possible to write the anonymous function using (value) → value. You can also use an anonymous parameter for the value to write the example like this: [ [3,5], [0.9,5.5] ] flatMap $. Note that this example produces the same result as flatten([ [3,5], [0.9,5.5] ]), which uses flatten.


%dw 2.0
output application/json
[ [3,5], [0.9,5.5] ] flatMap (value, index) -> value


[ 3, 5, 0.9, 5.5]

flatMap(Null, (item: Nothing, index: Nothing) -> Any): Null

Helper function that allows flatMap to work with null values.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub