Dataweave Array Difference

Viewed 59

I have 2 arrays. arr1 would be a superset and arr2 would be a subset and size of arr2 will always be less than arr1.

I'd like to find out what values in arr1 that are not in arr2.

e.g.

arr1 = [
  "07d65369-78eb-4afb-aba8-710ac146b93f",
  "15d65369-25eb-9u4b-6t7m-820ac145t8w1"
]
arr2 = [
  "07d65369-78eb-4afb-aba8-710ac146b93f"
]

The expected result should be ["15d65369-25eb-9u4b-6t7m-820ac145t8w1"]

1 Answers

Something like this maybe..

%dw 2.0
output application/json
var arr1 = [
  "07d65369-78eb-4afb-aba8-710ac146b93f",
  "15d65369-25eb-9u4b-6t7m-820ac145t8w1",
  "435rt3e-25eb-gh56-6t7m-njhyuiigt6565"
]
var arr2 = [
  "07d65369-78eb-4afb-aba8-710ac146b93f",
  "435rt3e-25eb-gh56-6t7m-njhyuiigt6565"
]
---
arr1 -- arr2
Related