web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to Merge 2 Arrays ...
Power Automate
Suggested Answer

How to Merge 2 Arrays without using Apply To Each Loop

(1) ShareShare
ReportReport
Posted on by 3
Hi everyone, I am currently trying to merge two arrays without having to use an apply to each loop as it is very inefficient.

I have my first array that looks something like this: [1,2,3,4,5,6,7,8,9,10]
And I have my second array that is an array of items: [{'ID': 3, 'data':'data3},{'ID': 5,'data':'data5'},{'ID': 6,'data':'data6'},{'ID': 8,'data':'data8'}}
And the resulting array needs to be something like: [1,2,{'ID': 3, 'data':'data3},4,{'ID': 5,'data':'data5'},{'ID': 6,'data':'data6'},7,{'ID': 8,'data':'data8'},9,10]

I managed to use a for loop and match each number to it's corresponding ID by checking if there is a valid id and if so update the array to include the item and if not just leave the number as is.

However I wonder if I can do this without using a for loop as it takes super long and is inefficient with larger data sets, I am open to ideas!

Thank you.
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,369 Super User 2025 Season 2 on at
    Hi
     
    Based on what you need, not sure what more you could do.
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at
    Hi,
     
    Yes it is possible by using xpath function. See below
     
     
     
    Use compose action to make the array2 prior to converting to xml as shown below
     
    Now in select action
     
    Now the main logic 
     
    Expression used- 
    if(equals(length(xpath(xml(outputs('Compose')),concat('//data[ID="',item(),'"]'))),0),item(),json(first(xpath(xml(outputs('Compose')),concat('//data[ID="',item(),'"]'))))?['data'])
     
     
    See the result of select action
     
    Hope it helps !
    Thanks & Regards,
    Nived N 
    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs
     Found my answer helpful? Please consider marking it as the solution!
     Your appreciation keeps me motivated. Thank you!

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard