# Return multiple Items from Code Node

**URL:** <https://community.n8n.io/t/return-multiple-items-from-code-node/19986>\
**Category:** Questions\
**Tags:** code\
**Created:** [November 20, 2022, 11:17pm UTC](https://community.n8n.io/t/return-multiple-items-from-code-node/19986 "2022-11-20T23:17:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnik](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/dnik/32/17282_2.png) [@dnik](https://community.n8n.io/u/dnik)\
**Post date:** [November 20, 2022, 11:17pm UTC](https://community.n8n.io/t/return-multiple-items-from-code-node/19986/1 "2022-11-20T23:17:29Z")

</div>

Hi everyone,

how can i return multiple Items from the Code Node? this is my first time using it since it replaced the function node and i cant get it to work.

I want to make several http-requests off an array from a single incoming Item.

No matter what i try, i am always forced to return a single item or it errors out.  
The relevant data is structured like this, i copied it from the node input json view:

```auto
[
  {
    "body": {
      "data": [359, 121, 223, 343]

    }
  }
]

```

Can you guide me in the right direction here? Any help is much appreciated!

---

<div class="post-metadata">

**Author:** ![dakota2gen](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@dakota2gen](https://community.n8n.io/u/dakota2gen)\
**Post date:** [November 21, 2022, 3:06am UTC](https://community.n8n.io/t/return-multiple-items-from-code-node/19986/2 "2022-11-21T03:06:41Z")

</div>

Can you provide an example workflow?

Maybe try adding items to the returned array itself

```auto
[
  {
    "body": {
      "data": 359

    }
  },
 {
    "body": {
      "data": 121

    }
  }
...
]

```

For example returning

```auto
return [
{
"name":
"First item",
"code":
1
},
{
"name":
"Second item",
"code":
2
}
]

```

gives me two items as output

---

<div class="post-metadata">

**Author:** ![dnik](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/dnik/32/17282_2.png) [@dnik](https://community.n8n.io/u/dnik)\
**Post date:** [November 21, 2022, 9:42am UTC](https://community.n8n.io/t/return-multiple-items-from-code-node/19986/3 "2022-11-21T09:42:57Z")

</div>

Thanks! I now got it to work, yet i don’t completely understand why.  
first, the tl;dr for others having this issue is:

```auto
let data = $input.first().json.data

return data.map((value)=> {
  return {json:{value}}
})

```

when there is only one incoming item to this node per workflow this does the trick. But this is also what confuses me.  
I had the node running in “Run once for each Item” mode because it sounded to me like the appropriate mode for this. "Run once for all Items " sounds like being mainly meant to be used for aggregating Information from multiple incoming nodes.  
I still cannot return multiple items in “Run once for each Item” mode, even when hardcoding the response. is there a way to do this?

---

<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:** [November 23, 2022, 11:43am UTC](https://community.n8n.io/t/return-multiple-items-from-code-node/19986/4 "2022-11-23T11:43:10Z")

</div>

When using the _Run once for each Item_ mode each incoming item must correspond to a result item and your code would only access a single item at a time.

So, while you wouldn’t have to worry about looping you also can’t change the total number of items in this mode. Or in other words, something like one incoming item to three result items won’t work in this mode. Does this make sense?

---

<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:** [February 21, 2023, 11:43am UTC](https://community.n8n.io/t/return-multiple-items-from-code-node/19986/5 "2023-02-21T11:43:21Z")

</div>

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