How to add new items in Code node

Describe the problem/error/question

Hi, i need to add multiple items to $input variable and remove the input item received from the previous node (i know that previous node will produce just 1 item). i have added my sample workflow, seems like it works but is this the correct approach ? Added screenshot, consoloe.log prints also the “pairedItem”:{“item”:0} do i also need to add it ?

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

[
  {
    "a": 1
  },
  {
    "b": 2
  },
  {
    "c": 3
  }
]

Information on your n8n setup

  • n8n version: 1.8.2
  • Database (default: SQLite): postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Mac OS Ventura 13.5.2

@slenderwrist , you do not need all that code in the Code node. Just ignore $input and return the data you need as in

return [
  {
    "a": 1
  },
  {
    "b": 2
  },
  {
    "c": 3
  }
];
1 Like

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