Common Items among Three Arrays

Hello UiPath Forum Experts,

I’m looking for a way to compare three arrays and return the items common to all three.

Example
Array 1: Email address; mailing address; Company; Country
Array 2: Email address; First Name; Last Name; Company; Country; Job Title
Array 3: Email address; University; Company; Country

In the above example, the results should be: Email Address; Company; and Country.
Thank you in advance.
You make life better for all of us.

Hi @PPIM_RPA ,

You could maybe try using the Intersect method :

array1.Intersect(array2).Intersect(array3).ToArray

array1, array2, array3 are variables of type Array of String.

Visual :
image

2 Likes

Hi @PPIM_RPA

Follow the below steps to achieve the required output:

  1. Initialize three arrays namely Array1,Array2,Array3 and give the following requied array. Datatype is Array(string).

Array1= {“Email address”, “mailing address”, “Company”, “Country”}
Array2= {“Email address”, “First Name”, “Last Name”, “Company”, “Country”, “Job Title”}
Array3= {“Email address”, “University”, “Company”, “Country”}

  1. Initialize an variable commonItems and datatype is Array(String).
  2. Take assign activity and by using Intersect method you can achieve the required output. Below are the syntax:

commonItems= Array1
commonItems= commonItems.Intersect(Array2).Intersect(Array3).ToArray()

  1. For For each Loop to achieve the output.

Note: Refer the below workflow file for reference.

Common Items in an Array.xaml (10.5 KB)
Hope it helps!!
Regards

Thank you for your detailed description with code.
Just confirmed that this works.
Appreciate it

1 Like

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