Function Node with multi-output

My Function node have 8 output. beacuse my msg.payload is a array. following code, Why always return value(it is a array[8]) to output1 :joy:

var outputMsgs = [];
var words = msg.payload;
for (var w in words) {
    outputMsgs.push({payload:words[w]});
}
return [ outputMsgs ];

not sure if I understand you correctly, but try
return outputMsgs;, since it is already an array

1 Like

Hi, in order to make code more readable and importable it is important to post it between two sets of three backticks - ``` - see this post for more details - How to share code or flow json

Your code is currently unreadable - please edit your post.

Secondly,

Read this the documentation on functions it tels you about sending multiple messages

Basically, its doing what you asked. (if you want 1 mesage for each output, remove the outer array e.g.

//return [ outputMsgs ]; << for sending multiple as per docs
return outputMsgs ; // << for sending 1 per output
1 Like

thank,following code, it work ok.

var outputMsgs = [];
var words = msg.payload;
for (var w in words) {
    outputMsgs.push({payload:words[w]});
}
return outputMsgs;
1 Like

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