Needing help with splitting a message into parts and having those

For instance the msg.payload is this:

I want to derive 4 variables:
time, r, g and b
to use in the same node to do things.

Unless i am misunderstanding:

let input = msg.payload.split(",")  // DayEnd,33,128,99

let time = input[0]
let r = input[1]
let g = input[2]
let b = input[3]


I just found that command and was in the process of testing it.

You posting it is good to see.

The die-hards would use consts instead of lets, but you get the gist :wink:

FYI, you can also assign the list of split parts to multiple vars like so:

let [time, r, g, b] = msg.payload.split(",");

Btw, if the split only returned 3 parts, the 4th variable would have the value undefined


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