In node-red dynamic output in function

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.

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]

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

if I use 1 as out put I am getting below out put with same response return:
chart1

Try

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

with one output

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

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