# Storing Array values to a single variable

**URL:** <https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690>\
**Category:** Studio\
**Tags:** activities-panel, question, studio, system, activities\
**Created:** [July 29, 2024, 9:01am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690 "2024-07-29T09:01:14Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![alan.prakash](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alan.prakash/32/263147_2.png) [@alan.prakash](https://forum.uipath.com/u/alan.prakash)\
**Post date:** [July 29, 2024, 9:01am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/1 "2024-07-29T09:01:14Z")

</div>

Hi Community,  
Suppose if i have one array for example {List1, List2, List3,List4}  
I need to loop through it and instead of showing output of array one by one i need to store the each output value to one variable and show it in a message box like  
“List1,List2,List3,List 4” please help to find the solution

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [July 29, 2024, 9:04am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/2 "2024-07-29T09:04:22Z")

</div>

`StringJoin(",", YourArrayWithLists.SelectMany(Function (x) x))`

---

<div class="post-metadata">

**Author:** ![mkankatala](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mkankatala/32/484097_2.png) [@mkankatala](https://forum.uipath.com/u/mkankatala)\
**Post date:** [July 29, 2024, 9:04am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/3 "2024-07-29T09:04:27Z")

</div>

Hi @alan.prakash

If you have stored all the variables List1, List2, List3 and List4 which have values in it.  
Then you want to print all the values in array variable. Let’s call array variable name as Arr\_Items.

Use the below expression to print,

```auto
String.Join(",", Arr_Items)

```

Hope it helps!!

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [July 29, 2024, 9:09am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/4 "2024-07-29T09:09:11Z")

</div>

> [@mkankatala](#):
>
> Use the below expression to print,
> 
> `String.Join(",", Arr_Items)`

In addition to above:  
 ![grafik](https://global.discourse-cdn.com/uipath/original/4X/f/9/9/f9958bea3590e33047c016445deb20e64ef19c34.png)  
And as mentioned above  
 ![grafik](https://global.discourse-cdn.com/uipath/original/4X/9/2/8/92813c7bce46dd66938ae27d5981d7b9236445b1.png)

---

<div class="post-metadata">

**Author:** ![rlgandu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rlgandu/32/488436_2.png) [@rlgandu](https://forum.uipath.com/u/rlgandu)\
**Post date:** [July 29, 2024, 9:14am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/5 "2024-07-29T09:14:16Z")

</div>

@alan.prakash

```auto
Assign: resultString = String.Join(",", listArray.SelectMany(Function(list) list))

```

---

<div class="post-metadata">

**Author:** ![Zidan\_Mohamed](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/zidan_mohamed/32/420561_2.png) [@Zidan\_Mohamed](https://forum.uipath.com/u/Zidan_Mohamed)\
**Post date:** [July 29, 2024, 9:18am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/6 "2024-07-29T09:18:55Z")

</div>

Let the array is of type ‘String’ (Array of String).

Initialize an output string, let’s say ‘outString’

You can just use a **for each** activity to loop through each item in the array.

Inside the **For Each** loop, use an **Assign** activity to concatenate each element to the output variable by using the expression the expression `outputString = outputString + item + ","`.

After(outside) the loop, use an **Assign** activity to remove the trailing comma using `outputString = outputString.TrimEnd(","c)`.

Finally, Use a **Message Box** activity to display `outputString`.

Regards:)

---

<div class="post-metadata">

**Author:** ![mkankatala](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/mkankatala/32/484097_2.png) [@mkankatala](https://forum.uipath.com/u/mkankatala)\
**Post date:** [July 29, 2024, 9:20am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/7 "2024-07-29T09:20:03Z")

</div>

This will work if the List1, List2, List3 and List4 are string datatype variables… @alan.prakash

If those variables are List datatype variables you can use the @ppr code with select many function or

Try the below expression,

```auto
String.Join(", ", Arr_Items.Select(Function(list) String.Join(", ", list)).ToArray())

```

Explanation -  
**Arr\_Items.Select(Function(list) list)** - Iterates through each list variable in the Arr\_Items array variable.  
**String.Join(“,” list).toarray()** - Joins the items in each list variable with a comma and stores the result in an array.  
**String.Join(", “, Arr\_Items.Select(Function(list) String.Join(”, ", list)).ToArray())** - Joins the array of concatenated list items with commas, producing a single string where all items from all lists are separated by commas.

![image](https://global.discourse-cdn.com/uipath/original/4X/1/4/f/14f700deaffc4f8a29ec3316e97d5585bb56c56f.png)

Based on your requirement use the expressions.

Hope you understand!!

---

<div class="post-metadata">

**Author:** ![Zidan\_Mohamed](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/zidan_mohamed/32/420561_2.png) [@Zidan\_Mohamed](https://forum.uipath.com/u/Zidan_Mohamed)\
**Post date:** [July 29, 2024, 9:21am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/8 "2024-07-29T09:21:10Z")

</div>

If it is an array of lists, then just use a for each loop inside the for each loop (Nested loop), one looping through each list and inside for each looping through each item in the list.

Rest everything will be the same.

Regards:)

---

<div class="post-metadata">

**Author:** ![Nawazish\_Ahmad](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nawazish_ahmad/32/262848_2.png) [@Nawazish\_Ahmad](https://forum.uipath.com/u/Nawazish_Ahmad)\
**Post date:** [July 29, 2024, 9:22am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/9 "2024-07-29T09:22:00Z")

</div>

Hi @alan.prakash

Try this in message box

* * *

`String.Join(",", ArrayVar)`

* * *

Your value will be display as comma separated, you can change according to your preference like `" ", "-", "|"`

Hope it helps !!

---

<div class="post-metadata">

**Author:** ![alan.prakash](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alan.prakash/32/263147_2.png) [@alan.prakash](https://forum.uipath.com/u/alan.prakash)\
**Post date:** [July 29, 2024, 9:42am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/10 "2024-07-29T09:42:42Z")

</div>

I need to use for each loop so each current item in a loop should append to it thats my case  
Suppose these are my array items{List1,List2,List3} i need to loop through it and inside loop i need to create a variable like output and it should be appended one by one

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [July 29, 2024, 9:48am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/11 "2024-07-29T09:48:32Z")

</div>

> [@alan.prakash](#):
>
> I need to use for each loop so each current item in a loop should append it thats my case

Just share some sample values and a more elaborated overall-goal description

> [@alan.prakash](#):
>
> show it in a message box

We shared the String.Join(…

> [@alan.prakash](#):
>
> i need to loop through it and inside loop i need to create a

For this we shared with you the SelectMany Part:

```auto
YourArrayWithLists.SelectMany(Function (x) x)

```

> [@alan.prakash](#):
>
> inside loop i need to create a variable like output and it should be appended one by one

We can merge all values into a list/array by single assign without for each

Assign Activity:  
`arrAllValues = YourArrayWithLists.SelectMany(Function (x) x).toArray`

---

<div class="post-metadata">

**Author:** ![alan.prakash](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alan.prakash/32/263147_2.png) [@alan.prakash](https://forum.uipath.com/u/alan.prakash)\
**Post date:** [July 29, 2024, 10:00am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/12 "2024-07-29T10:00:07Z")

</div>

I have attached one screenshot

 ![The image depicts a UiPath workflow with variables and activities, including an error marked in the assignment within a "For Each" loop that processes a list of items. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/7/2/e/72e2211eaee4b9cc0572699262e6a7d442b60020.png)  
i have used your logic but throwing error  
my use case is it need to create a string variable inside this loop like str\_output during the first iteration the value should be List1 in 2nd iteration value should be List1List2 like that, outside the for each loop i need to display that message as List1List2List3 During each iteration i need to concatinate the value

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [July 29, 2024, 10:04am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/13 "2024-07-29T10:04:04Z")

</div>

@alan.prakash  
dont mix up two things:

- flat string
- merged collection  
But for both, we gave the approaches:

And when during a loop the flat string is needed for the looped list then similar you can do:  
`Arr_SL = String.Join(",",arr_List)`

also you can do inspections / RnDs and Prototyping by using the debugging panels e.g. immediate panel:  
[Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum](https://forum.uipath.com/t/understanding-the-6-debugging-panels-of-uipath-in-the-easiest-way-possible/353606)

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [July 29, 2024, 10:10am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/14 "2024-07-29T10:10:39Z")

</div>

> [@alan.prakash](#):
>
> 2nd iteration value should be List1List2 like that,

When the need is really about:

- looping
- creating / concatenating looped list values to preivous looped values then we can do:

Variables:  
arrAllValues = String Array, Default Value: {}  
strFlatString  
For each Activity | item in {List1,List2,List3} | Type Argument: String List

- Log Message: `String.Join(",", item)`
- Assign activity: arrValues = `arrValues.Concat(item).toArray`
- Assign Activity: `strFlatString = strFlatString & "," & String.Join(",", item)`

---

<div class="post-metadata">

**Author:** ![Nawazish\_Ahmad](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nawazish_ahmad/32/262848_2.png) [@Nawazish\_Ahmad](https://forum.uipath.com/u/Nawazish_Ahmad)\
**Post date:** [July 29, 2024, 10:27am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/15 "2024-07-29T10:27:13Z")

</div>

@alan.prakash

Then Try this in you Assign Activity in you For Each Loop

**`output = IF(output = "", item, output + ", " + item)`**

Hope it helps !!  
Happy Automation :uipath:

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [August 1, 2024, 10:27am UTC](https://forum.uipath.com/t/storing-array-values-to-a-single-variable/756690/16 "2024-08-01T10:27:47Z")

</div>

Closed on August 1, 2024, 10:27am UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
