You have 2 options
- add the payload element to each text node, e.g
{{msg.payload[0]}}
in the value format field, 0 to 7 .
- split the array with a split node and use the msg.parts.index in a switch node property field to send to each text node, using rule
== 0
. 0 to 7
p.s node.send(newMsg)
or return newMsg
should be outside the loop, you are sending the payload 8 time with varying elements, rather than once with 8 elements. Also var neMsg = {}
should be before the loop.
[edit] Looking again the function is not even required. just use one of the options i suggested.
Example of option 1 with node-red-dashboard text nodes
[{"id":"d0da769320e30ab5","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6,7]","payloadType":"json","x":230,"y":40,"wires":[["77e8dca2af5bfa85","c769043b62334f2e"]]},{"id":"77e8dca2af5bfa85","type":"ui_text","z":"d1395164b4eec73e","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload[0]}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":410,"y":40,"wires":[]},{"id":"c769043b62334f2e","type":"ui_text","z":"d1395164b4eec73e","group":"8b5cde76.edd58","order":5,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload[1]}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":410,"y":80,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]
Example of option 2 with DB2 text nodes
[{"id":"d22816a2341152ef","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"one\",\"two\"]","payloadType":"json","x":454,"y":26.00000023841858,"wires":[["9c4556bbc7e2acac"]]},{"id":"9c4556bbc7e2acac","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":594,"y":26.00000023841858,"wires":[["7d5fb1326bcbdc61"]]},{"id":"7d5fb1326bcbdc61","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":714,"y":26.00000023841858,"wires":[["0e42041dcff44bb4","984e85a78eca56dc"],["9802e41f18e33d4e"]]},{"id":"0e42041dcff44bb4","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":26.00000023841858,"wires":[]},{"id":"9802e41f18e33d4e","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":66.00000023841858,"wires":[]},{"id":"984e85a78eca56dc","type":"debug","z":"d1395164b4eec73e","name":"debug 2562","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":714,"y":86.00000023841858,"wires":[]},{"id":"9d83cd8b3d5ee33c","type":"ui-group","name":"Group1","page":"c694d0ebe0d2b702","width":"6","height":"1","order":1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"c694d0ebe0d2b702","type":"ui-page","name":"Page1","ui":"1805777f90e92057","path":"/page1","icon":"home","layout":"grid","theme":"a965ccfef139317a","order":2,"className":"","visible":"true","disabled":"false"},{"id":"1805777f90e92057","type":"ui-base","name":"dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"a965ccfef139317a","type":"ui-theme","name":"HN Theme","colors":{"surface":"#5c5c5c","primary":"#00fdff","bgPage":"#383838","groupBg":"#4f4f4f","groupOutline":"#858585"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]
Option 2 would be more efficient as the array would not be cloned 7 times for each new wire.