Add element top array

Hello friends,

@rkelchuri, @Ninett_Panfir, @Rammohan91, @balupad14, @Florent_Salendres, @vvaidya, @Palaniyappan, @ClaytonM, @vvaidya, @lakshman, @Dave,

how to add element at the top of an array?
Thank you so much,
Cami

1 Like

Hi,
Adding element on top of which array?

Hello @vishal.kp,
a simple array of strings.
I need to add a string at the first position.
CAn you help me?

@CamiCat,

As per my knowledge you can not add the element in the begining of array. but you can add at end of the array.

if you want to modify/change the value in array you can do like below.

Array[0] = “value”;

Cheers,
Venkat.

Hi @CamiCat
We can’t insert element directly in the array at certain Position, but you can do one thing
Store your new value in Variable Lets say.
NewVar = "NewValue"
and Suppose your array is SampleArr.
Now, Convert this array in String and add your New Value in It Like this,
Str= NewVar+","+String.Join(",",SampleArr) .
Now split your string value using Str.Split(CChar(",")) and store this value in NewArray.
So your newvalue will be at first Position.
I hope this will help you.
Thanks & Regards

Hi @CamiCat,
First you need to convert your array to list using the variablename.toList . And then use the .add method to specify where you want to insert the element and then convert the list back to array.:slight_smile:

1 Like

Hello @vishal.kp,

have you got a solution?
Thank you,
Cami


you can refer this as example. :slight_smile:

Hi cami
Actually we won’t able to do that in a array rather we need to use a list variable
As Array is a fixed structure firstvwe won’t able to add a new element in even it is defined with a size
And so we can only insert values to a array with Arrayvariable.Insert(indexposition,”value”) and not possible to add an element

And to do that we need to use a List variable
We can use the same here and it is similar to array but more effective as we can add n number of element whenever we want
And to add a element in list variable
Listvariable.Insert(indexposition,”value”) with a simple assign activity

For more details on this

Cheers @CamiCat

Thank you so much @Palaniyappan,

I get this error.
Can you help me?


Cami

1 Like

@CamiCat I had used assign first . I was also getting the same error. Then i used the invoke method activity to call the same add function. it works fine

Thank you @vishal.kp,

I get this error


Can you help me?

Hi @CamiCat

You havent added a result variable

Thanks
Ashwin S

Kindly have a view on this topic
It got an example as well

Cheers @CamiCat

can you expand the second assign statement and show.

Thank you so much @Palaniyappan.
Cami

1 Like