# Using Outputs from Other nodes in "Code"

**URL:** <https://community.n8n.io/t/using-outputs-from-other-nodes-in-code/28404>\
**Category:** Questions\
**Tags:** code\
**Created:** [July 21, 2023, 1:13pm UTC](https://community.n8n.io/t/using-outputs-from-other-nodes-in-code/28404 "2023-07-21T13:13:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![N0ah](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n0ah/32/27637_2.png) [@N0ah](https://community.n8n.io/u/N0ah)\
**Post date:** [July 21, 2023, 1:13pm UTC](https://community.n8n.io/t/using-outputs-from-other-nodes-in-code/28404/1 "2023-07-21T13:13:24Z")

</div>

Hey all,

I have a code node that should transform the input as shown in the first picture if i hard Code the Input that works withput a Problem.

 ![Unbenannt](https://europe1.discourse-cdn.com/n8n/original/3X/3/2/32416ab181024fc316ba5bbdaa5b7cbd7a8688d8.png)

However, using a variable ($input.item) as the Input results in a ERROR: Cannot read properties of undefined (reading ‘Test’) [line 4, for item 0].

 ![Unbenannt1](https://europe1.discourse-cdn.com/n8n/original/3X/e/f/efe353266af8c1520f1aba47d3ac1a50677a03ad.png)

What am i doing wrong?, if the Code just is

```auto
const inputJSON = $input.item;
return inputJSON;

```

i get the correct Input as Output as i would othwise hard code it in as seen in the first picture…

How do i corectly refer the Input ?

---

<div class="post-metadata">

**Author:** ![marcus](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/marcus/32/15989_2.png) [@marcus](https://community.n8n.io/u/marcus)\
**Post date:** [July 21, 2023, 2:13pm UTC](https://community.n8n.io/t/using-outputs-from-other-nodes-in-code/28404/3 "2023-07-21T14:13:22Z")

</div>

Hey @N0ah,  
if your code is running in mode `Run Once For Each Item` the `$input.item` won’t be an array, it will be an object.

Can you try using `const inputJSON = $input.item.json.Test`?

---

<div class="post-metadata">

**Author:** ![N0ah](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n0ah/32/27637_2.png) [@N0ah](https://community.n8n.io/u/N0ah)\
**Post date:** [July 21, 2023, 2:36pm UTC](https://community.n8n.io/t/using-outputs-from-other-nodes-in-code/28404/4 "2023-07-21T14:36:14Z")

</div>

Hey @marcus,  
thanks for the quick answer, sadly that also doesnt do the job and returns a  
“ERROR: Cannot read properties of undefined (reading ‘forEach’) [line 11, for item 0]  
TypeError”

---

<div class="post-metadata">

**Author:** ![N0ah](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n0ah/32/27637_2.png) [@N0ah](https://community.n8n.io/u/N0ah)\
**Post date:** [July 21, 2023, 3:01pm UTC](https://community.n8n.io/t/using-outputs-from-other-nodes-in-code/28404/5 "2023-07-21T15:01:08Z")

</div>

after consulting it again with a fresh mind and some trial and error we came to conclude that it works with Run Once for Each Item and:

```auto
const inputJSON = $input.item;

// Extract the 'Test' array from the input JSON
const testArray = inputJSON.json.Test;

```

Thanks a lot for the help !

---

<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:** [October 19, 2023, 3:01pm UTC](https://community.n8n.io/t/using-outputs-from-other-nodes-in-code/28404/6 "2023-10-19T15:01:20Z")

</div>

Closed on October 19, 2023, 3:01pm UTC

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