Arrays are the collection type within Power Automate. They are an essential part of most Flows. This article explains how basic and advanced operations on arrays within a Power Automate Flow are implemented.
Since the article is created as a learning notebook for myself, you might know better solutions to a described problem. Do not hesitate to drop me a line, so I can adjust the article and learn from you.
- The Basics
- Advanced Operations
Create Array Variable / Initialize Array Variable
To create a Power Automate array variable, use the “Initialize variable” action.
Set Array Value
To set the value of an existing Power Automate array variable, use the “Set variable” action. (Overwrites current value.)
Add / Append Value to Array
To add a value to a Power Automate array, use the “Append to array variable” action. The sample below appends the string “purple” to the existing array colors.
Loop / Iterate over Array
To iterate over an array, use the “Apply to each” action.
In the example below 4 notificatrion emails are sent. One for every array element.
Array Length / Array Size
To evaluate the size of an array, use the length function.
In the example below, the condition evaluates to “true”, because the defined array “colors” has 3 elements.
Note: The length function can be used for variables of type array or string.
Access Array Element by Array Index
To access an array element by index, you can use the [<index>] from like below.
In the example “second color in array” will be “blue”. (Note: Index starts at zero=
Convert / Concat Array to String / Join Array to String
To convert an array to a string, use the Join action. Define the seperator to concat the values within the Join with option.
The result of the example below will be “green,blue,red”.
Convert a String to Array / Split a String into Array
To split a string into an array, you can use the split functions as follows.
The result of this example will be an array with these values: [ “green”, “blue”, “red”]
split(variables('colors as string'),',')
To my surprise, there is no sort function or action.
I’ve found these resources for workarounds.
- Sort an array in Power Automate in 3 easy steps
- How to implement Sort with Microsoft Flow in 3 actions within a loop
- Sort an array in Power Automate
Let me know, if there is a simpler solution.
Remove Duplicates from Array
To remove duplicate elements in an array, use the union function.
Note that we have to use the same array twice in our example.
The resulting array contains “blue” once.