Convert all values in array

This is one of my first exercises with Node-RED, so please be kind :wink:
I'm creating a simple dashboard to control my Modbus devices. Currently I can see the status of a few inputs and control the state of a few outputs. Now I want to slightly optimize the design.
Modbus-Read node gives me the following input:

msg.payload : array[8]
[ false, false, false, false, false, false, false, false ]

How can I convert [at once] each and every value in the array from true to On and false to Off?
Currently I'm converting every value like {{msg.payload[5]}} with individual Change nodes which is not nice.

one option - use a function node and array.map

give it a go.

If you get stuck, come back.

EDIT...
Heres a big sledgehammer clue...
image

1 Like

Many thanks! Working with the following code:

var data = msg.payload;
msg.payload = data.map(x => x ? "On" : "Off");
return msg;
2 Likes

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