Compare 2 arrays (current and previous attributes) and return values in current attributes that are not in the previous attributes array that can be mapped to subsequent modules

I have a webhook returning this basic structure:

{
    currentAttributes: ['val1', 'val2', 'val3'],
    prevAttributes: ['val1', 'val2']
}

I want to compare the 2 arrays and extract the value(s) from currentAttributes that are not in prevAttributes. In this example, I would need to extract the 'val3' string.

I need to be able to pass this string into another search step to find an item named val3

I’ve seen solutions using filters to continue the scenario if an array contains/does not contain a value, but a filter won’t work in this case because I need to pass along the unique value.

I’ve tried merging and deduplicating the array, but of course, a deduplicated array ['val1', 'val2', 'val3', 'val1', 'val2'] will still return ['val1', 'val2', 'val3'].

I’m thinking something along the lines of using the map() and/or toCollection() methods might be useful, but I’m still stuck on comparing and filtering to return only the value I want.

Basically the functionality I need would be this code:

const array1 = ["companyOne", "companyTwo", "companyThree"];
const array2 = ["companyOne", "companyTwo"];

const result = array1.filter(item => !array2.includes(item));

console.log(result); // This will log ["companyThree"]

Any advice is greatly appreciated, thanks!

1 Like

Hi @Allene_Norton

Two compare two arrays, please follow the steps explained in below link:

This will be a great guide to solve your issue.

Regards,
Msquare Automation - Gold Partner of Make

Book a Free Consultation | Connect Live

Explore our YouTube Channel for valuable insights and updates!

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of one module:

You’ll Iterate the Current Attributes,

Screenshot_2024-07-27_210731

Then filter the value if does not contain in Prev Attributes

Give it a go and let us know if you have any issues!

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!