Check if 2 arrays are similar


I have two arrays

Arr1 = {“1”,“15”,“7”,“36”}
Arr2 = {“1”,“15”,“8”,“14”}

and I want to check each array item if they are similar and output the following:
Arr3 = {“YES”,“YES”,“NO”,“NO”}

“Yes” if the items are the same, “No” if the items are not

Any suggestions on how to do this?
Thank you

1 Like


Do you mean want to check first element with first element only ?

Check per each element, so for the first element of Arr1 to the first element of Arr2 then to the second element of Arr1 to the second element of Arr2 and so on until the fourth element


Ok. Now got it.

First create one new array to write status. And then use nested ForEach loop to iterate two array.

       ForEach item1 in Arr1
            ForEach item2 in Arr2
                 IF item1.Tostring.Equals(item2)
                  Then use Add to Collection activity and pass "YES" and mention array name as Arr3
                   Else use Add to Collection activity and pass "NO" and mention array name as Arr3

Now Arr3 contains all statuses.



Welcome to UiPath Community!.

If you need to compare the two arrays sequentially and does not require the results in a third array, then you can use SequenceEqual of String array methods.

If you need to ignore the cases then pass this parameter as well,

strFirst.SequenceEqual(strSecond, StringComparer.OrdinalIgnoreCase)



I got a different answer from what I was expecting

I believe I looped Arr2 inside Arr1.

Where did I make a mistake?

Try this


Compare2Arrays.xaml (9.7 KB)

Check this xaml, it may help you.

1 Like


can you explain what condition you entered?:slightly_smiling_face:


item.Equals(arrSecond(Array.IndexOf(arrFirst, item)), StringComparison.InvariantCultureIgnoreCase)

item - Current Item from my arrFirst inside the loop
arrSecond - Second Array

Since I need to compare the 1st element from first array with the 1st element in the second array
I have used this,

arrSecond(Array.IndexOf(arrFirst, item))

Getting arrSecond array 1 index item using “Array.IndexOf” method
so here in arrSecond(0) item I need to take, so I am getting the item index value from first array.

StringComparison.InvariantCultureIgnoreCase - this is to ignore the case sentive string comparision



Why does Arr3 create an additional element?

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