2

I have a NodeRED flow which has a function node and my code is following

var left = { payload : msg.payload.readResults[0].v };
var right = { payload : msg.payload.readResults[1].v };
node.warn(left);
node.warn(right);
if(left || right)
{
    return [left,right];
}

Here I'm trying to get the both left and right outputs. The node.warn(left) and node.warn(right) tags give the outputs correctly but in the real return statement it outputs only left value when I have return[left,right]. When I have return left,right it returns right value.

How to get the both left and right values using return statement? Thank you!

enter image description here

Glenn94
  • 179
  • 1
  • 9
  • Why not just keep them in the msg object? Node-RED is all about passing msg around. – seb Jul 15 '22 at 21:05

1 Answers1

1

Finally figured it out, posting if incase anyone interested!

var left = {payload : msg.payload.readResults[0].v };
var right = {payload : msg.payload.readResults[1].v };


return [[left,right]];
Glenn94
  • 179
  • 1
  • 9
  • 2
    This is because when you return an array, the messages are written to the function nodes outputs based on array order, so with just a single dimension array `right` gets sent to the 2nd output (which doesn't exist). with to 2d array both get written to the first output – hardillb Jul 15 '22 at 21:46