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

Announcements

News and Announcements icon
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,960 Moderator on at
    Hi
     
    Based on what you need, not sure what more you could do.
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 251 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 239

#3
Expiscornovus Profile Picture

Expiscornovus 220 Most Valuable Professional

Last 30 days Overall leaderboard