Declare variable from previous nodes

Describe the problem/error/question

Hello everyone. How do I declare a variable from a previous node?

For example:

I have 10 code nodes configured in JavaScript in the workflow, the second node return an array with five objects, in the tenth node I want to declare that array with these five objects.

How do I set the variable? Like this: let array1 = $(‘Second Node’); ?

Information on your n8n setup

  • **n8n version:Latest
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):main
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):npm
  • **Operating system:Linux

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Hnk,

I am not sure why you flagged your post but I have restored it…

You can use a set node if you wanted to create a variable and use an expression to reference the output from a previous node or you can skip that and use the expression directly in a field somewhere.

You can find information on how to access the output of other nodes here: Output of other nodes | n8n Docs