1

i have dynamic array, meaning the value and length depends on my REST API call result.

i need to make that array has unique or distinct value, meaning the value inside the array must be unique to each other.

ANy idea?

Thanks

  • I found another way to dedupe array contents, using the [union](https://stackoverflow.com/a/56899290/117700) function. – Alex Gordon Jul 12 '19 at 19:24

2 Answers2

4

The linked comment using union shows how but does a bit more than the original request so those that want the very simple answer to the question - how do I get the unique/distinct values from an array - all you do is union the array with itself, i.e.

enter image description here

and the expression in the 2nd initialise just does:

union(variables('TestArray'),variables('TestArray'))
Simon
  • 1,613
  • 1
  • 12
  • 27
1

The ideal way to do this be passing exactly the data that you need into the logic app, and not require the logic app to do further processing on the area.

Suggestion 1: Feed the response from your function into another function that will return only the distinct values. Continue processing with your logic app without having the need to iterate through the entire array

Suggestion 2: Create an array variable. Iterate through your array with duplicates using the Foreach action. For each item() in the array that does not exist in your new array, add it.

Also, look at this answer regarding the union function.

Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • i thought about the suggestion 2, but when i tried it, it was not working as i need to created index to compare the new array index with the old array index. I may need to create foreach loop over and over again which i dunno how many as the length of array will be dynamic. – system programmer Jul 04 '19 at 04:01
  • 1
    logic apps are really not meant for this purpose, you are paying for every iteration of the foreach loop. correct if you were to follow my suggestion then inside of your foreach loop you would have to have another foreach loop to iterate through your other array. i would strongly suggest that you send to your logic app ONLY the data that the logic app needs, which means filtering out your unneeded data before it arrives to the logic app – Alex Gordon Jul 04 '19 at 16:42
  • you could also ask another question on stackoverflow asking "how do i do a left join between 2 arrays in a logic app" – Alex Gordon Jul 04 '19 at 16:43