I want to print 2D array
a!localVariables( local!a:{{1,2}, {3,4},{6,7}}, a!forEach( items: local!a, expression: fv!item ))
This will give below result
123467
But I want to print the result in below form
1,23,46,7
Discussion posts and replies are publicly visible
The issue here is that the array is being flattened and a!foreach() sees it as 6 items, vs 3 pairs of 2 items each. I'm not sure if we can unflatten it directly within a primitive data type.
Are you able to control the array, such as formatting it to key/value pairs? Such as:
a!localVariables( local!a: { {value: {1,2}}, {value: {3,4}}, {value: {6,7}} }, a!forEach( items: local!a, expression: joinarray(fv!item.value,",") ) )
Or, do we know that this data will always be an array of 2-valued nested arrays? Such as:
a!localVariables( local!a: {{1,2},{3,4},{6,7}}, a!forEach( items: 1+enumerate(count(local!a)/2), expression: joinarray( a!foreach( items: {fv!item*2-1,fv!item*2}, expression: index(local!a,fv!item,null) ), "," ) ) )
We can nix the nested a!foreach() in the second example above as well:
a!localVariables( local!a: {{1,2},{3,4},{6,7}}, a!forEach( items: 1+enumerate(count(local!a)/2), expression: joinarray(index(local!a,{fv!item*2-1,fv!item*2},null),",") ) )
Thanks Chirs for enhancing my knowledge.