Combine two arrays based on Index

Shalom Washington 0 Reputation points
2024-08-05T14:42:41.74+00:00

Hello everyone:

In my logic app, I've two arrays that I'd like to turn into 1 array of Key value pairs

Array one (columnNames):

["TimeGenerated","HeartbeatComputer","HeartbeatResourceId","AggregatedValue"]

Array two (columnValue):

["2024-07-25T18:59:36Z","spw-gener8logs","/subscriptions/4d4dea2b-026b-4e75-80ba-a567cbb39994/resourcegroups/rg-multitenant/providers/microsoft.compute/virtualmachines/spw-gener8logs",172725]

The goal is to turn these into a single array (without hardcoding values). I imagine it looking like:

[

columnNames[0] : columnValue[0],

columnNames[1] : columnValue[1],

columnNames[2] : columnValue[2],

]

All help appreciated!

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 17,866 Reputation points Moderator
    2024-08-05T19:40:33.5333333+00:00

    Hi @Shalom Washington Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    You can declare a variable of type Array and use the following dynamic content function in the action Set Variable to club the Arrays and assign the result.

    split(concat(variables('Array1')[0],':',variables('Array2')[0],';',variables('Array1')[1],':',variables('Array2')[1],';',variables('Array1')[2],':',variables('Array2')[2]
    ,';',variables('Array1')[3],':',variables('Array2')[3]
    ),';')
    
    
    

    Array1 and Array2 are local variables in my logic App which holds the array data to be merged. Replace the function with your appropriate local variable names and add any additional columns you may need to club

    Below is a reference image of the function and the runtime result

    User's image

    User's image

    Hope this helps! Please let me know if you run into any issues or need further clarification on this approach.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.