Msg.topic manipilation of output of a function node

A newbie question.... Again....

I have a function node that has a few outputs, what is the correct way of setting a different topic for a particular output?


return [ {payload:0}, {payload:1} ];

Sets the payloads for the outputs.... How do I set the topics (individually) for them too?


return [ {topic: "topic1", payload:0}, {topic: "topic2", payload:1} ];

Its just an object property.

A tiny bit of JS training around objects and arrays would help you greatly here. so here goes...

long hand version...

var msg1 = {}; //create an empty object
msg1.topic = "topic1"; //add a topic property
msg1.payload = 0; //add a payload property

var msg2 = {};//create an empty object
msg2.topic = "topic2";//add a topic property
msg2.payload = 1; //add a payload property

return [ msg1, msg2 ];

another version...

var msg1 = {
  topic : "topic1",
  payload : 0

var msg1 = {
  topic : "topic2",
  payload : 1

return [ msg1, msg2 ];

One more...

var messages = []; //an empty array
messages.push( {  topic : "topic1",  payload : 0 } ); //push an object into the array
messages.push( {  topic : "topic2",  payload : 1 } ); //push an object into the array
return messages; //return the array

hopefully that helps you understand some things?


Indeed it does!!

Thank you yet again!!


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