# IF node when iterate over multiple items

**URL:** <https://community.n8n.io/t/if-node-when-iterate-over-multiple-items/21185>\
**Category:** Questions\
**Tags:** if\
**Created:** [December 27, 2022, 3:27pm UTC](https://community.n8n.io/t/if-node-when-iterate-over-multiple-items/21185 "2022-12-27T15:27:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmarrot](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/fmarrot/32/12498_2.png) [@fmarrot](https://community.n8n.io/u/fmarrot)\
**Post date:** [December 27, 2022, 3:27pm UTC](https://community.n8n.io/t/if-node-when-iterate-over-multiple-items/21185/1 "2022-12-27T15:27:20Z")

</div>

![n8n_if_loop](https://europe1.discourse-cdn.com/n8n/original/3X/1/0/100e5d38c533e5fdfe948495001e10e80da5c020.png)

## I tried to figured out, how n8n handle the if node when iterate over multiple items?

I’ve set the **date\_in\_set\_node** variable in Set node, in function node I created multiple items ( **30** ) with the same value stored in **item\_date**

Then i need to check for each iterations, if value of the current iteration of **item\_date** is equal to the **date\_in\_set\_node** value using **if node**

I would like to understand why I only get **1 true** iteration in **First case** exemple, should I not get 30 true iterations ? The if node seems to stop iterations.

In **Second case** , I force the loop with a **splitInBatches** nodes and the result is **30 items true**.

In **Third case** , I use same function as other exemple, except that I push in newItems object the value of **date\_in\_set\_node** , in key **item\_set\_date** in **Function1** node.  
Then I compare if both values in the following **if** node are equal ( **item\_set\_date** == **item\_date** )  
So I also get as results **30 items true**.

Is **First case** a normal behaviour ? A bug ? A misunderstanding ? Something else ?

Thanks for your help !

## My workflow

## Information on my n8n setup

- **n8n version: 0.187.1**
- **MySQL Database**
- **Running n8n via desktop app**

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [December 28, 2022, 1:36pm UTC](https://community.n8n.io/t/if-node-when-iterate-over-multiple-items/21185/2 "2022-12-28T13:36:04Z")

</div>

> [@fmarrot](#):
>
> Is **First case** a normal behaviour ? A bug ? A misunderstanding ? Something else ?

Welcome to the community @fmarrot 🎉

In your _First case_ IF node you are using an expression of `{{$node["Set"].json["date_in_set_node"]}}`. The node does however receive 30 items. Now for the first item this IF node receives, it would look up the first item of on the Set node and read the `date_in_set_node` value for this item. This is working fine. However, for the second item it receives it would look up the second item from the Set node which does not exist. This is why 29 items are sent to the false output here.

So instead of of `{{ $node["Set"].json["date_in_set_node"] }}` you would want to use something like `{{ $items("Set")[0].json["date_in_set_node"] }}` to always read the first (and only) item from your Set node:

Afterwards, all items should go to the true output:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/0/f/0f6175283eb656e26e90829e3fc4926f9a0d4a81.png)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [January 4, 2023, 1:36pm UTC](https://community.n8n.io/t/if-node-when-iterate-over-multiple-items/21185/3 "2023-01-04T13:36:20Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
