How to add items into an array

Hello wonderful people,

How do I add items into a array of strings or any other data type?

Thanks for the help :slight_smile:

4 Likes

Hi,

See the attached test sequence for it.

Hope it will work
test_Array.xaml (5.2 KB)

Hi,
The below link can help for

Hi @cody.barber,

Try using an assign activity…

Example 1:
yourStringArray = yourStringArray.Concat({“newItem”}).ToArray

Example 2:
yourIntArray = yourIntArray.Concat({10}).ToArray

23 Likes

Thank you. :slight_smile:

1 Like

Thanks for the help :slight_smile:

Hi,

As a workaround you can convert an array to list, add as many items as you need and then eventually convert it back to the Array.

Array to list:
yourList = yourArray.ToList()

List to Array:
yourArray = yourList.ToArray()

Regards,
Kamil

2 Likes

When the default value for your Array is “new string(){}”. Assigning values to your array using arrayname.concat({item}).ToArray makes the array size dynamic.

3 Likes

Thank You . I was not putting a default value their

Although posting examples are great, the download and follow along post…

How can I add an array Item in 2D array?

This not works
2DArray.Concat({“Item1”,“Item2”,“Item3”,“Item4”}).ToArray

Also, I want the 2D array Initialize like this
2Darray = new string(15)(4){}
It not works too
image

This one works to add Array in 2D array.
2DArray.Append({“Item1”,“Item2”,“Item3”,“Item4”}).ToArray

If you work with dynamic sized collection then use list. If you have fixed size collection then use arrays.

But make sure that the Array was initialized, or you will have parameter null error. Just add default value in variable list.

The way you add items to an array depends on the programming language you are using. Here are some examples for a few popular programming languages:

In JavaScript: You can add items to an array using the push() method:

bashCopy code

let myArray = ["apple", "banana"];
myArray.push("orange");
console.log(myArray); // ["apple", "banana", "orange"]

In Python: You can add items to a list using the append() method:

scssCopy code

myList = ["apple", "banana"]
myList.append("orange")
print(myList) # ["apple", "banana", "orange"]

In Java: You can add items to an ArrayList using the add() method:

csharpCopy code

ArrayList<String> myList = new ArrayList<String>();
myList.add("apple");
myList.add("banana");
myList.add("orange");
System.out.println(myList); // ["apple", "banana", "orange"]

In C#: You can add items to a List using the Add() method:

mathematicaCopy code

List<string> myList = new List<string>();
myList.Add("apple");
myList.Add("banana");
myList.Add("orange");
Console.WriteLine(myList); // ["apple", "banana", "orange"]

Thank you, it works for me

1 Like