# Split not supported in function node

**URL:** <https://discourse.nodered.org/t/split-not-supported-in-function-node/90757>\
**Category:** General\
**Created:** [6 September 2024 18:01 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757 "2024-09-06T18:01:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ffich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ffich/32/27292_2.png) [@ffich](https://discourse.nodered.org/u/ffich)\
**Post date:** [6 September 2024 18:01 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/1 "2024-09-06T18:01:40Z")

</div>

Hi,  
I was trying the solution proposed in this post, to convert a numeric array into char:

> [@Convert decimal to char](https://discourse.nodered.org/t/convert-decimal-to-char/23496):
>
> Hi my friends, In part of my flow, I faced an output in decimal format like this : [{"id":"7c5d1a66.b99a74","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"74bc4c7d.bac1e4","type":"debug","z":"7c5d1a66.b99a74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":450,"y":80,"wires":[]},{"id":"4e14428e.9c0dac","type":"inject","z":"7c5d1a66.b99a74","name":"","topic":"","payload":"50, 54, 46, 48, 48,","pa…

But when I try Nick's solution, seems that the split method is not supported:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/afee4880858533b30678fb2f506bd061db7aefc0.png)

Anyone has an idea why?

I'm using NodeRed 3.1.9

BR

F.

---

<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:** [6 September 2024 18:14 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/2 "2024-09-06T18:14:22Z")

</div>

Msg.payload seems to be an array already so you would not require a split.  
Just use the map  
`msg.payload = msg.payload.map(v => parseInt(v))`

[edit]  
I also just noticed that your array seems to be integers already, so would also not require to be parsed to integers.  
So you can go straight to the  
`msg.payload = Buffer.from(msg.payload).toString();`

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [6 September 2024 18:17 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/3 "2024-09-06T18:17:26Z")

</div>

Education:

`split` creates an array, using a delimiter to identify the elements (example : `,`) , but as @E1cid pointed out - you already have an array (already split)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 September 2024 19:19 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/4 "2024-09-06T19:19:31Z")

</div>

> [@ffich](#):
>
> convert a numeric array into char

Your data is a buffer. You can either use the buffer-parser node (install from palette) or a function with ...

```auto
msg.payload = msg.payload.toString()
return msg

```

---

<div class="post-metadata">

**Author:** ![ffich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ffich/32/27292_2.png) [@ffich](https://discourse.nodered.org/u/ffich)\
**Post date:** [7 September 2024 16:19 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/5 "2024-09-07T16:19:55Z")

</div>

> [@E1cid](#):
>
> msg.payload = Buffer.from(msg.payload).toString();

Yeah, but I don't simply want to shows those bytes as string. I actually want to convert the numeric values to their string equivalent, so that I can display them with a text node. If I simply do a 'toString' conversion i see just garbage (not printable ASCII or no meaning stuff).

Hope I made myself clear...

---

<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:** [7 September 2024 16:32 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/6 "2024-09-07T16:32:55Z")

</div>

Still not crystal.  
but try

```auto
msg.payload = [...msg.payload].map(asi => String.fromCharCode(asi))

```

should return

```auto
["\u000b","\t","","I","Ø"]

```

when feed your buffer.  
or

```auto
msg.payload = String.fromCharCode(...msg.payload)

```

if you do not want an array.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 September 2024 18:23 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/7 "2024-09-07T18:23:43Z")

</div>

> [@ffich](#):
>
> I actually want to convert the numeric values to their string equivalent, so that I can display them with a text node

To show them in "a text node" implies 1 string.

So what exactly should this string contain?

- `[11, 5, 127, 73, 216]`
- `11, 5, 127, 73, 216`
- `11 5 127 73 216`
- `11512773216`
- Something else?

Please be clear.

---

<div class="post-metadata">

**Author:** ![ffich](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ffich/32/27292_2.png) [@ffich](https://discourse.nodered.org/u/ffich)\
**Post date:** [8 September 2024 19:50 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/8 "2024-09-08T19:50:25Z")

</div>

Hi,  
Apologize for the unclear explanation. Both bullet points 2 and 3 are fine. The bytes in the array are received from an uart channel and are part of a specific communication protocol.

Anyhow, speaking with a friend much mooooore confident with JavaScript than me, I've found the line of code that does what I need:

msg.payload = msg.payload.map(i =\>i.toString()).join(" ")

Using this in a function node does the conversion I need to correctly visualize the array in a dashboard text node.

Thanks everyone  
F.

---

<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:** [8 September 2024 20:01 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/9 "2024-09-08T20:01:44Z")

</div>

So now we know more prcisely, then you do not need to map or toString just  
`msg.payload = [...msg.payload].join(" ");`  
should do what you wish.

---

<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:** [22 September 2024 20:01 UTC](https://discourse.nodered.org/t/split-not-supported-in-function-node/90757/10 "2024-09-22T20:01:54Z")

</div>

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