# Needing help with splitting a message into parts and having those

**URL:** <https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434>\
**Category:** General\
**Created:** [16 February 2022 06:45 UTC](https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434 "2022-02-16T06:45:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [16 February 2022 06:45 UTC](https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434/1 "2022-02-16T06:45:59Z")

</div>

For instance the `msg.payload` is this:  
`DayEnd,33,128,99`

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 February 2022 07:13 UTC](https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434/2 "2022-02-16T07:13:33Z")

</div>

Unless i am misunderstanding:

```auto
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]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [16 February 2022 07:14 UTC](https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434/3 "2022-02-16T07:14:50Z")

</div>

Thanks.

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

You posting it is good to see.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [16 February 2022 07:17 UTC](https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434/4 "2022-02-16T07:17:05Z")

</div>

The die-hards would use `const`s instead of `let`s, but you get the gist 😉

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [16 February 2022 16:21 UTC](https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434/5 "2022-02-16T16:21:32Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 March 2022 16:22 UTC](https://discourse.nodered.org/t/needing-help-with-splitting-a-message-into-parts-and-having-those/58434/6 "2022-03-02T16:22:13Z")

</div>

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