cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

how to set nth element in array

Hi all,

 

how can I set/update the nth Element of an already populated array in Flow without iterating through all values in a foreach-loop?

if I have "myArray" and an index "n":

I think of something like

   variables('myArray')[n] = 'my new value'

or

  set(variables('myArray')[n] , 'my new value')

 

but even if the syntax is ok, where to put that???

 

thanks,

 

Axel

 

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: how to set nth element in array

Hi @AHu,

 

I assume that you could try the replace function to replace an old value with a new value.

 

Please check the following doc on the replace function for more details:

https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#r...

 

 

Best regards,

Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Frequent Visitor

Re: how to set nth element in array

Hi Mabel,
thank you for answering...

Well, "replace" seems to be good, but since I'm a newb to flow: where to put it?

I tried in a compose-action:
(where "inidizesProcessed" is an array of, say, 4 elements, each "0" (string)
and "myLoopIndex" an Integer which counts iterations in a foreach-loop.)

 

foreach:

condition if yes:
  compose:
  replace( variables('indizesProcessed')[variables('myLoopIndex')] , '0' , '1')

The result should be something like
Array[
 "0",
 "1",
 "0",
 "0"
]
with "1" set only in position n, where some condition is fulfilled,

but it seems that the compose action does not change the array:

This is the resulting "indizesProcessed":

Typ
Array
Wert
[
  "0",
  "0",
  "0",
  "0"
]

I'm pretty sure the problem is somewhere in my head but do you have any idea where???

Best regards,
Axel

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Users online (8,518)