Can we use forEach operator in Code node?

Getting this error when using this operator in the n8n code node:


payload.listeSurveyQuestion.forEach((question) => {
const questionObj = {
title: question.title,
answers: ,

Error: ERROR: Cannot read properties of undefined (reading ‘forEach’) [line 6]

ERROR: Cannot read properties of undefined (reading ‘forEach’) [line 6]

Please share your workflow

Share the output returned by the last node

ERROR: Cannot read properties of undefined (reading ‘forEach’) [line 6]

Information on your n8n setup

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

@cmorneau , I believe you have a typo

// payload includes listeSurveyQuestion already
const payload = $node["Build Survey Answers Array"].json.listeSurveyQuestion;

// you reference listeSurveyQuestion again, 
// aka `$node["Build Survey Answers Array"].json.listeSurveyQuestion.listeSurveyQuestion`
payload.listeSurveyQuestion.forEach((question) => ...)

Try payload.forEach((question) => ...) instead.

You still have error but they are down the code at the later step.


Thanks for the quick reply, especially at this time of the year ! This fixed it Ihor.

Have a great rest-of-day!


1 Like

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