I need to compare two arrays that have different data fields in them. The comparison is based on lets say Id number and if data matches in the two arrays, I need to remove the whole block/row from the array. For example, in the below arrays, I need to compare OrderId(from Array1) and SystemId(from Array2) and if the Ids match the whole block needs to be removed from Array1. Please see sample arrays and output below:
Array1 = [
{
"OrderId": "00111111",
"BillingCountry": "GB",
"CurrencyIsoCode": "GBP",
"PersonEmail": "[email protected]"
},
{
"OrderId": "00222222",
"BillingCountry": "US",
"CurrencyIsoCode": "USD",
"PersonEmail": "[email protected]"
}
]
Array2 = [
{
"SystemId": "00111111"
},
{
"SystemId": "00333333"
},
{
"SystemId": "00444444"
}
]
Output: [
{
"OrderId": "00222222",
"BillingCountry": "US",
"CurrencyIsoCode": "USD",
"PersonEmail": "[email protected]"
}
]
I believe for these kind of problem using the Arrays module some() function express the intention clearly.
Output