# Split values in a string?

**URL:** <https://discourse.nodered.org/t/split-values-in-a-string/52974>\
**Category:** General\
**Created:** [30 October 2021 12:56 UTC](https://discourse.nodered.org/t/split-values-in-a-string/52974 "2021-10-30T12:56:07Z")\
**Posts on this page:** 1\
**Showing post:** 12

<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:** [30 October 2021 16:01 UTC](https://discourse.nodered.org/t/split-values-in-a-string/52974/12 "2021-10-30T16:01:49Z")

</div>

First, please don't post code as an image. Use the method described in [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506). That would have saved me having to type out bits of the code again.

Change  
`let data = ""`  
which initialises data to an empty string so that when you add the other ones it concatenates the text rather than adding the numbers  
to  
`let data = 0`

In fact even better would be to use Array method `reduce()`. See [Array.prototype.reduce() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce)

---

_[View the full topic](https://discourse.nodered.org/t/split-values-in-a-string/52974)._
