cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AHu
Level: Powered On

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
Community Support Team
Community Support Team

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
AHu
Level: Powered On

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

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Users Online
Currently online: 314 members 4,455 guests
Please welcome our newest community members: