# \`msg.payload.split\` is not a function. Help

**URL:** https://discourse.nodered.org/t/msg-payload-split-is-not-a-function-help/53974
**Category:** General
**Created:** [19 November 2021 03:14 UTC](https://discourse.nodered.org/t/msg-payload-split-is-not-a-function-help/53974 "2021-11-19T03:14:40Z")
**Posts on this page:** 4
**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: [19 November 2021 03:14 UTC](https://discourse.nodered.org/t/msg-payload-split-is-not-a-function-help/53974/1 "2021-11-19T03:14:40Z")

</div>

I am seeing this error:

```auto
{"message":"TypeError: msg.payload.split is not a function","source":{"id":"3445206e.094b08","type":"function","name":"ADD values","count":1}}

```

Ok....

Just before this node is a `change` node:

```auto
[{"id":"f901977f.2dbaa8","type":"change","z":"a1911aa3.c45be8","d":true,"name":"get `existing`","rules":[{"t":"set","p":"existing","pt":"msg","to":"LEDSTRIP","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":760,"wires":[["3445206e.094b08"]]}]

```

(It is disabled because the next bit isn't working)

The idea is that I have some addressable RGB LEDs.  
When a message comes through to _change_ the colour, it is added to the existing colour.

So, say it is showing `30,0,0`

A new message comes to show `0,20,0`  
The result would be the message becomes `30,20,0` and sent to the LED.

This is the code:

I know I don't like _smart_ commands which compound several into one line.  
I am not sure that I am falling into that here.  
If so: I didn't mean to do it.

```auto
// Get LED number from `payload`
//let led = parseInt(msg.payload.split(",")[1]);
let payload = msg.payload
let blah = payload.split(","[1]);

let led = parseInt(blah);

if (led > 4)
{
    // Get RGB values from `payload`
    let n_red = parseInt(msg.payload.split(",")[2])
    let n_green = parseInt(msg.payload.split(",")[3])
    let n_blue = parseInt(msg.payload.split(",")[4])

    let existing_value = msg.existing[led];
    // Now get existing RGB values.
    if (existing_value == undefined)
    {
        existing_value = "0,0,0";
    }
    let x_red = parseInt(existing_value.split(",")[0]);
    let x_green = parseInt(existing_value.split(",")[1]);
    let x_blue = parseInt(existing_value.split(",")[2]);

    let red = n_red + x_red;
    let green = n_green + x_green;
    let blue = n_blue + x_blue;

// node.warn("Values " + n_red + " " + n_green + " " + n_blue);
// node.warn("Stored values " + x_red + " " + x_green + " " + x_blue);
// node.warn("Added values " + red + " " + green + " " + blue);
}

if (msg.payload.who == "All clear")
{
    //
    // Wipe the alarm LEDs
    //
    // work needed
}

return msg;

```

---

<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: [19 November 2021 05:46 UTC](https://discourse.nodered.org/t/msg-payload-split-is-not-a-function-help/53974/2 "2021-11-19T05:46:47Z")

</div>

> let blah = payload.split(","[1]);

Little mistake there

`let blah = payload.split(",")[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: [19 November 2021 05:52 UTC](https://discourse.nodered.org/t/msg-payload-split-is-not-a-function-help/53974/3 "2021-11-19T05:52:33Z")

</div>

There is still more work to do, but that's my problem. Thanks.

---

<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: [3 December 2021 05:53 UTC](https://discourse.nodered.org/t/msg-payload-split-is-not-a-function-help/53974/4 "2021-12-03T05:53:08Z")

</div>

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