Is it possible to update/replace the nth element of an array
input =[1,2,3,4]
Update 3rd element from 3 to 5
Output=[1,2,5,4]]
In ADF, self-referencing variables is not supported. So, use a temporary variable first and then reassign that temporary variable value to required one.
If you only want to do it in ADF and not in dataflow, follow the below approach.
I have created two array variables named x
with values [1,2,3,4]
and temp
.
I have created two parameters for nth element and updated value.
X value at start:
I have used the below expression to get the updated array.
@createArray(take(variables('x'),sub(pipeline().parameters.nth,1)),pipeline().parameters.value,skip(variables('x'),pipeline().parameters.nth))
This will give output like below.
To get the array in required format, use the below expression and assign the value to required variable.
@json(concat('[',replace(replace(string(variables('temp')), '[', ''),']',''),']'))
Result: