Node function with 2 msg

I am playing around with node-red and want to learn more...

Problem i cant solve is how to create two msg(msg1 and msg2) in a function
This must be the output

//input msg for function
// test0: "test0"

// test0: "test0"
// test1: "test0"

// msg2
// test0: "test0"
// test2: "test2"

I can create twe two msg within the function, but msg2 only contains var test and not the old input content .

test = {"test2":"test2"}    // new extra var for msg2. But how do i add old msg ?

// add var to current msg

msg2=test;  // how do i also add content of msg1 (current msg)

There are lots of ways of doing this - they are all just JavaScript objects in the end.
Something like:

var msg1 = {
   test0: msg.test0,
   test1: "test0"

var msg2 = {
   test0: msg.test0,
   test2: "test2"

return [msg1,msg2]

That part was the part that was working...

But what if msg2 has to contain (test2: "" test2) like you did AND ALL the content of the input message of the function.

something like msg2=msg + {test2: "test2"}

var msg1 = RED.util.cloneMessage(msg);
var msg2 = RED.util.cloneMessage(msg);

// now update msg1 and msg2 with whatever extra properties you want
msg1.test = "red";
msg2.test = "blue";

return [msg1,msg2]

Thanks @knolleary, that works!

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