# Split a Message

**URL:** <https://discourse.nodered.org/t/split-a-message/32254>\
**Category:** General\
**Created:** [31 August 2020 14:44 UTC](https://discourse.nodered.org/t/split-a-message/32254 "2020-08-31T14:44:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RAULXXX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/raulxxx/32/27989_2.png) [@RAULXXX](https://discourse.nodered.org/u/RAULXXX)\
**Post date:** [31 August 2020 14:44 UTC](https://discourse.nodered.org/t/split-a-message/32254/1 "2020-08-31T14:44:11Z")

</div>

Hi everyone,

i am trying to get the last 3 positions of the payload of this message

31/8/2020 16:37:23[node: SWITCH 5](http://localhost:1880/#)test : msg.payload : string[25]

""DB0020\_AUTO".PRUEBA5,101"

I need 101 value, but i dont want a split after "," because in this way i would get 2 messages and i dont kwow how to differenciate between the variable name ("DB0020\_AUTO".PRUEBA5) and the value 101

in other way i wrote a function in order to get the last positions of the array but doesnt work

message = msg.payload  
A =   
A[0] = message[25]  
A[1] = message[24]  
A[2] = message[23]

msg=A;

return msg;

thank you for any clue in any way

---

<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:** [31 August 2020 14:56 UTC](https://discourse.nodered.org/t/split-a-message/32254/2 "2020-08-31T14:56:43Z")

</div>

In a function node you could use:

```auto
m = msg.payload.split(",")
msg.value = parseInt(m[1])

return msg

```

Output

![Screenshot 2020-08-31 at 16.56.27](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5ca423a69b38ac73263ef2762d4ea550bd5ae276.jpeg)

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [31 August 2020 15:02 UTC](https://discourse.nodered.org/t/split-a-message/32254/3 "2020-08-31T15:02:36Z")

</div>

> [@bakman2](#):
>
> In a function node you could use:
> 
> ```auto
> m = msg.payload.split(",")
> 
> ```

@bakman2 No offence but I really think you should use a keyword to declare the variables in your examples, just to not teach bad practices to people new to JS. It's not Python even if Node-RED doesn't use a strict interpreter 🙂.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 August 2020 15:03 UTC](https://discourse.nodered.org/t/split-a-message/32254/4 "2020-08-31T15:03:41Z")

</div>

Or if you want the answer in the payload then

```auto
msg.payload = parseInt(msg.payload.split(",")[1])
return msg

```

If you want the answer left as a string then

```auto
msg.payload = msg.payload.split(",")[1]
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:** [31 August 2020 15:13 UTC](https://discourse.nodered.org/t/split-a-message/32254/5 "2020-08-31T15:13:42Z")

</div>

No offence taken, it is a keyword: short for message 😉

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [31 August 2020 15:18 UTC](https://discourse.nodered.org/t/split-a-message/32254/6 "2020-08-31T15:18:56Z")

</div>

🙄

---

<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:** [30 October 2020 15:19 UTC](https://discourse.nodered.org/t/split-a-message/32254/7 "2020-10-30T15:19:03Z")

</div>

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