# In node-red dynamic output in function

**URL:** <https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664>\
**Category:** General\
**Created:** [6 March 2019 12:57 UTC](https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664 "2019-03-06T12:57:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [6 March 2019 12:57 UTC](https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664/1 "2019-03-06T12:57:53Z")

</div>

In node-red I wanted the dynamic function output based on message length as I am integrating with chart having multiple line(so message will be in array). So, I wanted the output node of function to be based on function length. But as shown in the below image we have to manually configure the output node. I tried to change the out to msg.payload.length but it won't take that and again by default it'll change to 1.

 ![function](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e33f9a4cff03215db4a7c98bb2226e18404cdf04.png)

---

<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:** [6 March 2019 13:37 UTC](https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664/2 "2019-03-06T13:37:12Z")

</div>

Why do you need them on multiple outputs? Could you just send a sequence of messages instead? So instead of  
`return msgarr`  
use  
`return [msgarr]`

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [6 March 2019 14:10 UTC](https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664/3 "2019-03-06T14:10:47Z")

</div>

I am using chart node with below payload returning in function node to chart node.

`return [{ topic: 'line1', payload: 5.699999809265137 },{ topic: 'line2', payload: 1.5 }];`

if I use 2 as out put I am getting below out put with same response return:  
 ![chart2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/29b9289dc188382ee3ddcb5fe7cae22c7c4d01d1.png)

if I use 1 as out put I am getting below out put with same response return:  
 ![chart1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b94a1456d061dbfc39ab06c9f24645e1f58b01c4.png)

---

<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:** [6 March 2019 14:14 UTC](https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664/5 "2019-03-06T14:14:16Z")

</div>

> [@VIKRAMAS](#):
>
> return [{ topic: 'line1', payload: 5.699999809265137 },{ topic: 'line2', payload: 1.5 }];

Try

```auto
return [[{ topic: 'line1', payload: 5.699999809265137 },{ topic: 'line2', payload: 1.5 }]];

```

with one output

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [6 March 2019 14:16 UTC](https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664/6 "2019-03-06T14:16:22Z")

</div>

thank you working!! I thought as I am passing array so no need of passing inside one more array, but know I got it.

---

<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:** [6 March 2019 14:19 UTC](https://discourse.nodered.org/t/in-node-red-dynamic-output-in-function/8664/7 "2019-03-06T14:19:34Z")

</div>

If you return an array then it tries to send one element to each output. If you send an array of arrays then the first element of the outer array goes to output 1, but since that is also an array it sends a sequence of messages to that output. See the sections on multiple messages and multiple outputs in [https://nodered.org/docs/writing-functions](https://nodered.org/docs/writing-functions)
