cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Vshandilya
Microsoft
Microsoft

Compare 2 complex array and get a value from 2nd array

 I have these two arrays:

Array 1 is

[

{

   "Name"" test",
    "Age""22"
},

{

   "Name"" test 1",
    "Age""35"
}
]
 
and Array 2 is
 

[

{

   "Name"" test",
    "email""test@com"
},

{

   "Name"" test 1",
    "email""test_1@com"
}
]

and I want to compare each "Name" Values of array and get the "email" or "Age" value in flow

need Help in this tried everything possible not getting solution
1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Vshandilya,

Do you want to join two arrays based on the same Name?

 

Here is a simple demo, please check as below.

vqiaqimsft_0-1656384352242.png

vqiaqimsft_4-1656384976464.png

Firstly, you should write your two arrays within two separate Compose as below:

vqiaqimsft_1-1656384388843.png

Then you should add an Apply to each to loop through the first array. Note that you should filter the second array within the Filter array. 

Write the following expression to compare the Name field from array 1 with the Name field in array 2. Just click the "Edit in advanced mode".

@equals(item()?['Name'], items('Apply_to_each')?['Name'])

vqiaqimsft_2-1656384489674.png

Add a new Compose and write the following expression:

{
  "Name": " test",
  "Age": @{items('Apply_to_each')?['Age']},
  "email": @{first(body('Filter_array'))?['email']}
}

Then add another new compose outside the Apply to each, reference to the compose3 as below:

outputs('Compose_3')

vqiaqimsft_3-1656384921994.png

 

 

 

Best Regards,
Qi

View solution in original post

3 REPLIES 3
Vshandilya
Microsoft
Microsoft

Both Array Has different elements and Values too. I need the values of which have same "name"

Hi @Vshandilya,

Do you want to join two arrays based on the same Name?

 

Here is a simple demo, please check as below.

vqiaqimsft_0-1656384352242.png

vqiaqimsft_4-1656384976464.png

Firstly, you should write your two arrays within two separate Compose as below:

vqiaqimsft_1-1656384388843.png

Then you should add an Apply to each to loop through the first array. Note that you should filter the second array within the Filter array. 

Write the following expression to compare the Name field from array 1 with the Name field in array 2. Just click the "Edit in advanced mode".

@equals(item()?['Name'], items('Apply_to_each')?['Name'])

vqiaqimsft_2-1656384489674.png

Add a new Compose and write the following expression:

{
  "Name": " test",
  "Age": @{items('Apply_to_each')?['Age']},
  "email": @{first(body('Filter_array'))?['email']}
}

Then add another new compose outside the Apply to each, reference to the compose3 as below:

outputs('Compose_3')

vqiaqimsft_3-1656384921994.png

 

 

 

Best Regards,
Qi
Vshandilya
Microsoft
Microsoft

Hey @v-qiaqi-msft Thanks, it helped me.

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (5,529)