Help with function node -string type output

Hey all can can someone advise how to make this function node to work

if (msg.payload === "A") {
return [ "true" , "false" , "false" , "false" , "false" , "false" ,"false" ];
else if (msg.payload === "B"){
return [ "false", "true", "false", "false", "false", "false" ,"false" ];
else if (msg.payload === "C"){
return [ "false", "false", "true", "false", "false", "false" ,"false" ];
else if (msg.payload === "D"){
return [ "false", "false", "false", "true", "false", "false" ,"false" ];
else if (msg.payload === "E"){
return [ "false", "false", "false", "false", "true", "false" ,"false" ];
else if (msg.payload === "1"){
return [ "false", "false", "false", "false", "false", "true" ,"false" ];
else if (msg.payload === "0"){
return [ "false" , "false", "false", "false", "false", "false" ,"false" ];


It says that function tried to sent a message of type string


Hi. So few things...

  1. Returning an array from a function node is intended for when you have multiple outputs on the function note.

  2. the return value from a function node must always be an object (or array of objects). If you intend on sending an array, assign it to the message payload property.

Try this....

msg.payload = [ "false" , "false", "false", "false", "false", "false" ,"false" ]
return msg;

To simplify the function node (less maintenance)

m = msg.payload

char = "ABCDE10".split("")
out = [false,false,false,false,false,false,false]  // default all false
o = char.indexOf(m)

    out[o] = true

return {payload:out}

ie; all false unless...

example output


Thanks guys both methods working perfect

@bakman2 - where does the ...,"input":"A"} come from in your example?


it was to show that it the input matches with the expected output.

Hmmm, I wish I had that magic since I didn't get that using your code :worried:

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