IF Node Values Exist

Hello.

I can’t figure how to check if a value from an array of some node

[
{
"Source": "bbb"
}
] 

is exist in another array from another node

[
{
"Destination": "aaa"
},
{
"Destination": "bbb"
},
{
"Destination": "ccc"
}
] 

so that IF Node returns true and procceds.

Any ideas?

This would require some custom JS. I assume the array from another node is an array of multiple n8n items? If so, here’s a quick example I’ve whacked together using the $items method and JavaScript’s .includes(). You should be able to adjust it to your needs even if your data structure is slightly different:

Example Workflow

This will add an isInArray field to each input item, telling you whether your String is in the array:

You could the use this field in your IF node. Hope this helps getting started :slight_smile:

1 Like

Yes it’s working fantastic

I didn’t know the use case for Function Item node.

Is it used as i understand to loop through items returned from another node?

The documentation here

that says Check out this page to learn about the difference between the two. returns a 404 error page.

Where can i found this page to learn more?

Thank you again!

Glad to hear this is working, thanks a lot for confirming!

The correct link should be: Key concepts | Docs, sorry for the 404. The main difference is indeed that the Function Item node loops through all incoming items (whereas the Function node gets executed only once).

In the above example workflow this would allow you to perform the lookup for multiple items as it would check for each input item whether the value appears in the referenced array.

Hope this makes sense :slight_smile:

1 Like

Hi @Mulen,

I was speaking to @maxT about this today and he suggested another approach that I did overlook earlier.

As a code-free approach, you could also use the Merge node’s Keep Key Matches mode to keep only the matching items:

Example Workflow

image

The merge node also has a Remove Key Matches mode in case you want to find items that are not part of your array. Hope this makes life a tad easier for you :slight_smile:

2 Likes

Indeed i tried to replicate it in my setup and both ways now work.

Thank you very much again for your effort!

1 Like