# Split a string into separate values

**URL:** <https://discourse.nodered.org/t/split-a-string-into-separate-values/23979>\
**Category:** General\
**Created:** [31 March 2020 13:19 UTC](https://discourse.nodered.org/t/split-a-string-into-separate-values/23979 "2020-03-31T13:19:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rysig](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Rysig](https://discourse.nodered.org/u/Rysig)\
**Post date:** [31 March 2020 13:19 UTC](https://discourse.nodered.org/t/split-a-string-into-separate-values/23979/1 "2020-03-31T13:19:17Z")

</div>

Hello,  
I'm new and I'd like to get some help to split a string into separate elements in NodeRed.  
As an example,

- my msg.payload is '11110110'
- and I like to get separate data/lines (array) such as 1, 1, 1, 1, 0, 1, 1 and 0  
Can I do this with "split" and how?  
Thanks again!  
David

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [31 March 2020 13:33 UTC](https://discourse.nodered.org/t/split-a-string-into-separate-values/23979/2 "2020-03-31T13:33:19Z")

</div>

You can use the split node to get 8 seperate messages

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c9b30782ade29bc6b2ea678ee0cd85062e93ca8.png)

You can then use the join node to get those into an array

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/111ce4d028f2a9ba0c32ef20297d859896c8ddc9.jpeg)

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [31 March 2020 14:14 UTC](https://discourse.nodered.org/t/split-a-string-into-separate-values/23979/3 "2020-03-31T14:14:25Z")

</div>

Above solution is perfect. Alternatively you could use below piece of code inside a function node.

```auto
msg.payload = [...msg.payload];
return msg;

```

This way an incoming string will be changed to an array.

---

<div class="post-metadata">

**Author:** ![Rysig](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Rysig](https://discourse.nodered.org/u/Rysig)\
**Post date:** [31 March 2020 19:47 UTC](https://discourse.nodered.org/t/split-a-string-into-separate-values/23979/4 "2020-03-31T19:47:54Z")

</div>

Ok many 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:** [30 May 2020 19:48 UTC](https://discourse.nodered.org/t/split-a-string-into-separate-values/23979/5 "2020-05-30T19:48:03Z")

</div>

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