The block "Compare lists" can be used to find common or unique items between 2 given lists (arrays).

The block takes 2 lists as input:

Example settings:

When you choose "Intersect" for the option "Compare results", you can choose how the result is returned by this block:

Example lists

Example list 1:

[
      {"email": "john@doe.com", "name": "John Doe"},
      {"email": "bill@acme.com", "name": "Bill Davis"}
]

Example list 2:

[
      {"email": "john@doe.com", "city": "NY"},
      {"email": "ann@acme.com", "city": "Paris"}
]

Unique keys

Enter the key on which objects in each list will be compared. For example "email" in one list and "profile.email" in the second. Objects will be matched/merged based on the values from these keys.

Compare results

Unique in list 1 (all items in list 1 that do not exist in list 2)

If we match on keys "email", the result of the above example lists will be:

[
      {"email": "bill@acme.com", "name": "Bill Davis"}
]

Note: if you want to have objects that are unique in list 2, you should switch both lists and use the option "unique in list 1".

Intersect (all items that exist in both list 1 and list 2)

If we match on keys "email", and you set the "Results" option to "Items from list 1", the result of the above example lists will be:

[
      {"email": "john@doe.com", "name": "John Doe"}
]

If we match on keys "email", and you set the "Results" option to "Merged items from list 1 and list 2", the result of the above example lists will be:

[
      {"email": "john@doe.com", "name": "John Doe",  "city": "NY"}
]

Iterator

This block does not use an iterator, which means that both input lists will be loaded in memory before doing the compare. This means that a Blend using this block will fail with an "out of memory" error for very large lists.

Did this answer your question?