# Split the string into separate values

**URL:** <https://discourse.nodered.org/t/split-the-string-into-separate-values/2818>\
**Category:** General\
**Created:** [4 September 2018 05:40 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818 "2018-09-04T05:40:16Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [7 September 2018 07:27 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/42 "2018-09-07T07:27:21Z")

</div>

> [@ukmoose](#):
>
> Please export your flow and paste it in this thread in between ``` so it formats it correctly

You didn't paste it in between ``` please EDIT your last post to correct this.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [7 September 2018 07:38 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/44 "2018-09-07T07:38:03Z")

</div>

OK try this to get the idea...

flow surrounded by ``` so that you can import it...

`[{"id":"7ec7ffcd.3ac498","type":"inject","z":"9a50778a.ed93a","name":"PIR1-OFF","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":132.5,"y":165,"wires":[["84a1dbfa.6173a8"]]},{"id":"56c07777.086f9","type":"inject","z":"9a50778a.ed93a","name":"PIR1-ON","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":132,"y":209,"wires":[["84a1dbfa.6173a8"]]},{"id":"81635019.8a1f28","type":"inject","z":"9a50778a.ed93a","name":"PIR2-OFF","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":127,"y":304,"wires":[["29430074.7cd92"]]},{"id":"729cd490.f7fdd4","type":"inject","z":"9a50778a.ed93a","name":"PIR2-ON","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":126.5,"y":348,"wires":[["29430074.7cd92"]]},{"id":"84a1dbfa.6173a8","type":"change","z":"9a50778a.ed93a","name":"","rules":[{"t":"set","p":"PIR1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":306.5,"y":185,"wires":[["d0b0375.0457c48"]]},{"id":"29430074.7cd92","type":"change","z":"9a50778a.ed93a","name":"","rules":[{"t":"set","p":"PIR2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":302,"y":323,"wires":[["d0b0375.0457c48"]]},{"id":"d0b0375.0457c48","type":"switch","z":"9a50778a.ed93a","name":"PIR1 STATE","property":"PIR1","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":538.5,"y":240,"wires":[["936b1670.26f43"],["ad2a52e6.e304a8"]]},{"id":"936b1670.26f43","type":"switch","z":"9a50778a.ed93a","name":"PIR2 STATE","property":"PIR2","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":721.5,"y":172,"wires":[["4c64d149.5070a8"],["5cbd381e.f58b2"]]},{"id":"ad2a52e6.e304a8","type":"switch","z":"9a50778a.ed93a","name":"PIR2 STATE","property":"PIR2","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":723,"y":276,"wires":[["bc642787.6d91f8"],["abf9401b.bbf108"]]},{"id":"4c64d149.5070a8","type":"debug","z":"9a50778a.ed93a","name":"PIR1 OFF PIR2 OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":960.5,"y":83,"wires":[]},{"id":"bc642787.6d91f8","type":"debug","z":"9a50778a.ed93a","name":"PIR1 ON PIR2 OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":953,"y":235,"wires":[]},{"id":"5cbd381e.f58b2","type":"debug","z":"9a50778a.ed93a","name":"PIR1 OFF PIR2 ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":960,"y":153,"wires":[]},{"id":"abf9401b.bbf108","type":"debug","z":"9a50778a.ed93a","name":"PIR1 ON PIR2 ON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":952,"y":293,"wires":[]}]`

Flow requires both a PIR1 and PIR2 input before it starts...  
There are many ways to do this but hopefully this way will help you understand what you need to do...

---

<div class="post-metadata">

**Author:** ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)\
**Post date:** [7 September 2018 08:19 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/50 "2018-09-07T08:19:41Z")

</div>

sorry there is some problem with my keyboard

---

<div class="post-metadata">

**Author:** ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)\
**Post date:** [7 September 2018 08:27 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/51 "2018-09-07T08:27:28Z")

</div>

`[{"id":"76332ed6.a6db3","type":"mqtt in","z":"8eb88f3b.85ef2","name":"","topic":"NODE01","qos":"2","broker":"ce2b3222.963ee","x":60,"y":260,"wires":[["5dc1f66e.f73328"]]},{"id":"5dc1f66e.f73328","type":"function","z":"8eb88f3b.85ef2","name":"datanode1","func":"var output = msg.payload.split(\",\");\n \nvar temp = parseFloat(output[0]);\nvar humidity = parseFloat(output[1]);\nvar pir = parseInt(output[2]);\nvar ldr = parseInt(output[3]);\nvar msg0 = {payload:temp};\nvar msg1 = {payload:humidity};\nvar msg2 = {payload:pir};\nvar msg3 = {payload:ldr};\nreturn [msg0 , msg1 , msg2 , msg3];\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","outputs":4,"noerr":0,"x":210,"y":260,"wires":[["1554e13f.4c59ef"],["effa5112.982a7"],["b5c683b0.1f49d","d23ed03a.2e08a","e53998e.4dc2468","1554e13f.4c59ef"],["b5c683b0.1f49d","e53998e.4dc2468"]]},{"id":"b6f533da.49d11","type":"trigger","z":"8eb88f3b.85ef2","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"5","extend":true,"units":"s","reset":"","bytopic":"all","name":"TIME OUT","x":870,"y":260,"wires":[["dfcf0f10.5751"]]},{"id":"dfcf0f10.5751","type":"debug","z":"8eb88f3b.85ef2","name":"MOVEMENT DETECTED","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":850,"y":360,"wires":[]},{"id":"bccd3ae5.bfccf8","type":"switch","z":"8eb88f3b.85ef2","name":"CONDITION(FAN)","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"0","vt":"num"},{"t":"btwn","v":"10","vt":"num","v2":"15","v2t":"num"},{"t":"btwn","v":"16","vt":"num","v2":"20","v2t":"num"},{"t":"btwn","v":"21","vt":"num","v2":"25","v2t":"num"},{"t":"btwn","v":"26","vt":"num","v2":"50","v2t":"num"}],"checkall":"true","repair":false,"outputs":5,"x":430,"y":100,"wires":[["282ffb4.26aec04"],["d079e9f6.acc6d8"],["eb28c799.893088"],["879261c.e5c20a"],["688a3f53.613a4"]]},{"id":"d079e9f6.acc6d8","type":"debug","z":"8eb88f3b.85ef2","name":"SPEED 25%","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":80,"wires":[]},{"id":"eb28c799.893088","type":"debug","z":"8eb88f3b.85ef2","name":"SPEED 50%","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":120,"wires":[]},{"id":"282ffb4.26aec04","type":"debug","z":"8eb88f3b.85ef2","name":"FAN OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":680,"y":40,"wires":[]},{"id":"879261c.e5c20a","type":"debug","z":"8eb88f3b.85ef2","name":"SPEED 75%","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":160,"wires":[]},{"id":"688a3f53.613a4","type":"debug","z":"8eb88f3b.85ef2","name":"SPEED 100%","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":680,"y":200,"wires":[]},{"id":"e4f8b311.196e1","type":"switch","z":"8eb88f3b.85ef2","name":"CONDITION(LIGHT)","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"200","vt":"num"},{"t":"btwn","v":"200","vt":"num","v2":"500","v2t":"num"},{"t":"btwn","v":"500","vt":"num","v2":"750","v2t":"num"},{"t":"gte","v":"750","vt":"num"}],"checkall":"true","repair":false,"outputs":4,"x":560,"y":440,"wires":[["8ed94bd6.4d6c28"],["de8fbd40.a6f5d"],["60b3efdb.0a646"],["c9433f6d.a9fbd"]]},{"id":"8ed94bd6.4d6c28","type":"debug","z":"8eb88f3b.85ef2","name":"NO LIGHT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":830,"y":420,"wires":[]},{"id":"de8fbd40.a6f5d","type":"debug","z":"8eb88f3b.85ef2","name":"1 LIGHT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":820,"y":460,"wires":[]},{"id":"60b3efdb.0a646","type":"debug","z":"8eb88f3b.85ef2","name":"2 LIGHT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":820,"y":500,"wires":[]},{"id":"effa5112.982a7","type":"debug","z":"8eb88f3b.85ef2","name":"HUMIDITY","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":450,"y":180,"wires":[]},{"id":"7cadd8d8.6aea88","type":"debug","z":"8eb88f3b.85ef2","name":"NO MOVEMENT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":320,"wires":[]},{"id":"b5c683b0.1f49d","type":"switch","z":"8eb88f3b.85ef2","name":"PIR (1)","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":260,"wires":[["680e7da0.1c1504"]]},{"id":"680e7da0.1c1504","type":"switch","z":"8eb88f3b.85ef2","name":"VALUE OF LDR","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"0","vt":"num","v2":"1024","v2t":"num"}],"checkall":"true","repair":false,"outputs":1,"x":660,"y":260,"wires":[["b6f533da.49d11"]]},{"id":"d23ed03a.2e08a","type":"switch","z":"8eb88f3b.85ef2","name":"PIR (0)","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":420,"y":320,"wires":[["7cadd8d8.6aea88"]]},{"id":"e53998e.4dc2468","type":"switch","z":"8eb88f3b.85ef2","name":"PIR(1,0)","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":440,"wires":[["e4f8b311.196e1"],["8ed94bd6.4d6c28"]]},{"id":"1554e13f.4c59ef","type":"switch","z":"8eb88f3b.85ef2","name":"PIR(1,0)","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":200,"y":100,"wires":[["bccd3ae5.bfccf8"],["282ffb4.26aec04"]]},{"id":"ce2b3222.963ee","type":"mqtt-broker","z":"8eb88f3b.85ef2","name":"","broker":"192.168.11.52","port":"1883","clientid":"clientID01","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":null,"birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willRetain":null,"willPayload":""}]`

---

<div class="post-metadata">

**Author:** ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)\
**Post date:** [7 September 2018 08:28 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/52 "2018-09-07T08:28:17Z")

</div>

take a look at my flow.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 September 2018 09:48 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/53 "2018-09-07T09:48:57Z")

</div>

Attach a debug node to each of the outputs of the function node and see what shows up.

---

<div class="post-metadata">

**Author:** ![Srijan](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Srijan](https://discourse.nodered.org/u/Srijan)\
**Post date:** [7 September 2018 09:54 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/54 "2018-09-07T09:54:58Z")

</div>

value of ldr, pir, temp,humidity

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [7 September 2018 11:19 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/55 "2018-09-07T11:19:44Z")

</div>

OK so you are sending temp AND PIR to the `PIR(1,0)` node.

But you only check to see if `msg.payload` is `1` or `0` i.e. PIR on or OFF.  
If `msg.payload` is 1 you then check to see if `msg.payload` is either LESS THAN 0 or between 10 & 50. But the switch only passes on values of 1, which isn't one of the options.

My suggestion would be to store the PIR value as a flow variable ( see my earlier flow example uses a `Change` node to set `flow.PIR` to `msg.payload`) and then from the temp output from your function have a `Switch` node that checks on the status of `flow.PIR`

---

<div class="post-metadata">

**Author:** ![Kr4ntz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kr4ntz/32/5564_2.png) [@Kr4ntz](https://discourse.nodered.org/u/Kr4ntz)\
**Post date:** [31 January 2019 05:14 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/56 "2019-01-31T05:14:55Z")

</div>

The world needs more people like you, mate.

---

<div class="post-metadata">

**Author:** ![eddy23](https://avatars.discourse-cdn.com/v4/letter/e/a587f6/32.png) [@eddy23](https://discourse.nodered.org/u/eddy23)\
**Post date:** [27 June 2020 08:47 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/57 "2020-06-27T08:47:01Z")

</div>

> [@hotNipi](#):
>
> [{"id":"df6d6c66.b6c4e","type":"split","z":"d9f8d1d.5cd143","name":"","splt":",","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":820,"wires":[["fe502aa1.ee37c8","3ba2aff1.e8af5"]]},{"id":"d9822859.20a7b8","type":"inject","z":"d9f8d1d.5cd143","name":"","topic":"","payload":"15.4,50,23.8,79","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"","x":220,"y":820,"wires":[["bc23045.f5103f8","df6d6c66.b6c4e"]]},{"id":"2f990562.44d8ea","type":"debug","z":"d9f8d1d.5cd143","name":"out 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":760,"wires":},{"id":"fe502aa1.ee37c8","type":"change","z":"d9f8d1d.5cd143","name":"to number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":820,"wires":[["9052efa8.e5f0a","d6f23ad6.490eb8"]]},{"id":"9052efa8.e5f0a","type":"switch","z":"d9f8d1d.5cd143","name":"route","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":750,"y":820,"wires":[["2f990562.44d8ea"],["35825546.228baa"],["d5e60d8b.47391"],["d97cb86c.da9478"]]},{"id":"35825546.228baa","type":"debug","z":"d9f8d1d.5cd143","name":"out 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":800,"wires":},{"id":"d5e60d8b.47391","type":"debug","z":"d9f8d1d.5cd143","name":"out 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":840,"wires":},{"id":"d97cb86c.da9478","type":"debug","z":"d9f8d1d.5cd143","name":"out 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":930,"y":880,"wires":},{"id":"2f3bddd7.cf80e2","type":"comment","z":"d9f8d1d.5cd143","name":"split","info":"Split comma separated string into separated messages.\nValue placed to msg.payload\nValue type will be still string.\n\nThere will be 4 messages out of this split node\n\nFor each msg also given a property "parts". \nIt will be used later on.","x":410,"y":760,"wires":},{"id":"d4a6401f.81de4","type":"comment","z":"d9f8d1d.5cd143","name":"convert","info":"Convert the value of msg.payload to the number using JSONata expression.\n","x":590,"y":760,"wires":},{"id":"60cbfa64.9cb4b4","type":"comment","z":"d9f8d1d.5cd143","name":"route","info":"Route every message to differet output by using switch node.\nAs property "parts" has been given to each message, we can use its \n"index" property to find out proper output\n\n","x":750,"y":760,"wires":},{"id":"bc23045.f5103f8","type":"debug","z":"d9f8d1d.5cd143","name":"source data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":410,"y":980,"wires":},{"id":"3ba2aff1.e8af5","type":"debug","z":"d9f8d1d.5cd143","name":"spltted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":940,"wires":},{"id":"d6f23ad6.490eb8","type":"debug","z":"d9f8d1d.5cd143","name":"converted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":660,"y":900,"wires":}]

This really helped me a lot thank you

---

<div class="post-metadata">

**Author:** ![nmwakde](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@nmwakde](https://discourse.nodered.org/u/nmwakde)\
**Post date:** [29 July 2020 11:21 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/58 "2020-07-29T11:21:30Z")

</div>

hi Srijan,  
I am facing the same problem.  
can you help me to split a string into 4 real separate values?  
i am trying to write the function code but not getting the result.

 ![node red12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97c9744374917a0c3984e3ae605e73bcfe902fc1.jpeg)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 July 2020 12:07 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/59 "2020-07-29T12:07:11Z")

</div>

Here is one way to do it. Use a `change` node to remove the `[]` with two replaces of nothing, then use a jsaoata expression - `$split(payload,',')` - to 'split' the remainder into an array  
 ![Screen Shot 2020-07-29 at 8.06.16 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cd7e195ca68fa4ee112f144220aac34c3216d6dc.png)

```auto
[{"id":"846aa32f.9c4a4","type":"change","z":"196c2b5b.d805c5","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"[","fromt":"str","to":"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"]","fromt":"str","to":"","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"$split(payload,',')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":360,"wires":[["df4e419b.5e2c4"]]}]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [29 July 2020 12:53 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/60 "2020-07-29T12:53:38Z")

</div>

or just feed it into a json node which will output the array...  
and then maybe into a split node to send 4 values... if needed.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [29 July 2020 13:49 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/61 "2020-07-29T13:49:07Z")

</div>

Much better than my idea!!

---

<div class="post-metadata">

**Author:** ![Orchitis](https://avatars.discourse-cdn.com/v4/letter/o/a87d85/32.png) [@Orchitis](https://discourse.nodered.org/u/Orchitis)\
**Post date:** [17 December 2020 22:50 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/62 "2020-12-17T22:50:51Z")

</div>

Thanks so much for posting the example flow. It helps us beginners tremendously and makes learning Node Red a little easier.

---

<div class="post-metadata">

**Author:** ![Rob1](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rob1](https://discourse.nodered.org/u/Rob1)\
**Post date:** [13 April 2022 21:47 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/63 "2022-04-13T21:47:37Z")

</div>

![Schermafbeelding 2022-04-13 om 23.42.09](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c18f1aac817a6b7a0d40c56eef6c3e340929d770.png)

Hi, I read the things above but can't seem to get the values of t1 and t2 to put in a graph.

I got this far:  
var output = msg.payload.split(",");

var t1 = parseInt(output[0]);  
var t2 = parseInt(output[1]);  
var p = parseFloat(output[2]);  
var msg0 = {payload:t1};  
var msg1 = {payload:t2};  
var msg2 = {payload:p};  
return [msg0 , msg1 , msg2];

But I guess I get NaN because msg0 is: t1:20.26 But I just want the number/value.

---

<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:** [14 April 2022 04:53 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/64 "2022-04-14T04:53:23Z")

</div>

> [@Rob1](#):
>
> But I guess I get NaN because msg0 is: t1:20.26 But I just want the number/value.

Correct, you would need to remove everything up to the `:` before you try to use `parseInt` function. Try splitting again on the colon, to separate the key from the value, like this:

```auto
var output = msg.payload.split(",");
var [k1, v1] = split(output[0], ':');
var t1 = parseInt(v1);

```

I like to use a `change` node with a JSONata expression that uses a regular expression to find all of the `key:val` pairs, and reassemble them into a single object:

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

Here is the expression I used:

```auto
payload.$match(/([^:]*):([-.\d]+)[,\n]?/).[groups] {
    $[0]: $number($[1])
}

```

The nice thing about having all the keys and values is a single msg object is that you can pass the same data around to multiple ui nodes, and each one can choose which value to display by specifying the field name.

But I know that's pretty advanced syntax, and most people don't like it because it may be hard for someone else to maintain that code in the future. If you prefer to use a Javascript function, you may be able to get away with `eval`uating that string wrapped in curly braces, like so:

```auto
eval("msg.payload = {" + str + "}");
return msg;

```

But that is usually not good practice -- it relies too heavily on the format of the data string to be valid JS object syntax.

---

<div class="post-metadata">

**Author:** ![Rob1](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rob1](https://discourse.nodered.org/u/Rob1)\
**Post date:** [14 April 2022 20:34 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/65 "2022-04-14T20:34:16Z")

</div>

Hi shrickus, Thanks for the help I'm going to try the first part of your reply, that's already difficult enough for me :-). I know almost nothing about coding that's why I like Node red.

![Schermafbeelding 2022-04-14 om 22.47.23](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c069320fc3350bbe965604cbd186ee040601f246.png)

I did this:  
var output = msg.payload.split(",");  
var [k1, v1] = split(output[0], ':');  
var t1 = parseInt(output[0]);  
var t2 = parseInt(output[1]);  
var p = parseFloat(output[2]);  
var msg0 = {payload:t1};  
var msg1 = {payload:t2};  
var msg2 = {payload:p};  
return [msg0 , msg1 , msg2];

But got the above error. Like I said I'm a Noob in coding. Do not Know what k1 and v1 does?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 April 2022 21:08 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/66 "2022-04-14T21:08:32Z")

</div>

Try

```auto
msg = msg.payload.split(":").slice(1,4).map(e => {
    return {payload:parseFloat(e)}
});
return msg;

```

---

<div class="post-metadata">

**Author:** ![Rob1](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rob1](https://discourse.nodered.org/u/Rob1)\
**Post date:** [17 April 2022 06:32 UTC](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818/67 "2022-04-17T06:32:22Z")

</div>

> [@E1cid](#):
>
> ```auto
> .slice(1,4).map(e => {
> return {payload:parseFloat(e)}
> });
> 
> ```

E1cid, Thanks.

var output = msg.payload.split(",").slice(1,4).map(e =\> {  
return {payload:parseFloat(e)}  
});

var t1 = parseInt(output[0]);  
var t2 = parseInt(output[1]);  
var p = parseFloat(output[2]);  
var msg0 = {payload:t1};  
var msg1 = {payload:t2};  
var msg2 = {payload:p};  
return [msg0 , msg1 , msg2];

![Schermafbeelding 2022-04-17 om 08.20.39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/9557e46451e8b41a8e4868d8380e9f321bbbf074.png)

[Previous page](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818.md?page=2)

[Next page](https://discourse.nodered.org/t/split-the-string-into-separate-values/2818.md?page=4)
