Create array of objects in a change node?

Trying to create/populate an array of objects via a change node... to avoid creating a function node and line code to do same. I at times need to prime an array, say initialize array that is sent to a table, that is later updated for example.

I know how to create an object via a change node but I have not cracked how to create an array of objects via change node. This has got to be easy... just have not figured the trick out as yet.

[{"id":"8b0c8ba2.f5e33","type":"inject","z":"332b4aa4.d68ec6","name":"Set Sonic 17,18","props":[{"p":"topic","vt":"str"},{"p":"payload"},{"p":"payload.trigger","v":"17","vt":"num"},{"p":"payload.echo","v":"18","vt":"num"},{"p":"payload.temperature","v":"20.0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"command/irrigation/TestListener/set/sonic/0","payload":"{}","payloadType":"json","x":180,"y":1620,"wires":[["69ba475c.3d234"]]},{"id":"b46851af.47c1b","type":"inject","z":"332b4aa4.d68ec6","name":"Set Sonic Sensors .0 17,18","props":[{"p":"topic","vt":"str"},{"p":"payload"},{"p":"payload.0","v":"[]","vt":"json"},{"p":"payload.0.trigger","v":"17","vt":"num"},{"p":"payload.0.echo","v":"18","vt":"num"},{"p":"payload.0.temperature","v":"20.0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"command/irrigation/TestListener/set/sonic","payload":"[]","payloadType":"json","x":160,"y":1660,"wires":[["69ba475c.3d234"]]},{"id":"5819d158.5a28e8","type":"inject","z":"332b4aa4.d68ec6","name":"Set Sonic Sensors [0] 17,18","props":[{"p":"topic","vt":"str"},{"p":"payload"},{"p":"payload[0]","v":"[]","vt":"json"},{"p":"payload[0].trigger","v":"17","vt":"num"},{"p":"payload[0].echo","v":"18","vt":"num"},{"p":"payload[0].temperature","v":"20.0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"command/irrigation/TestListener/set/sonic","payload":"[]","payloadType":"json","x":160,"y":1700,"wires":[[]]}]

Here is a function node that creates a small array, an example of what I want to do via a change node.

[{"id":"b46851af.47c1b","type":"inject","z":"332b4aa4.d68ec6","name":"Set Sonic Sensors 0,1,2","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"command/irrigation/TestListener/set/sonic","payload":"","payloadType":"date","x":190,"y":1660,"wires":[["cfc0ea85.3fa0e"]]},{"id":"cfc0ea85.3fa0e","type":"function","z":"332b4aa4.d68ec6","name":"0,1,2","func":"const SENSORS=[\n        { trigger: 17, echo: 18, temperature: 20.0 },\n        { trigger: 19, echo: 20, temperature: 20.0 },\n        { trigger: 21, echo: 22, temperature: 20.0 }\n    ];\n\nmsg.payload=SENSORS;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":1660,"wires":[["c6fcca0.a2829b8"]]}]

you can set the Change node to Json with the diffrence that you have to surround the object properties with double quotes.

[{"id":"b46851af.47c1b","type":"inject","z":"af25975e21b17ff4","name":"Set Sonic Sensors 0,1,2","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"command/irrigation/TestListener/set/sonic","payloadType":"date","x":410,"y":1320,"wires":[["cfc0ea85.3fa0e","04b082de14c0891b"]]},{"id":"cfc0ea85.3fa0e","type":"function","z":"af25975e21b17ff4","name":"0,1,2","func":"const SENSORS = [\n    { trigger: 17, echo: 18, temperature: 20.0 },\n    { trigger: 19, echo: 20, temperature: 20.0 },\n    { trigger: 21, echo: 22, temperature: 20.0 }\n];\n\nmsg.payload = SENSORS;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":1280,"wires":[["ecb3a10dbce136d3"]]},{"id":"ecb3a10dbce136d3","type":"debug","z":"af25975e21b17ff4","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":770,"y":1280,"wires":[]},{"id":"04b082de14c0891b","type":"change","z":"af25975e21b17ff4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[{\"trigger\":17,\"echo\":18,\"temperature\":20},{\"trigger\":19,\"echo\":20,\"temperature\":20},{\"trigger\":21,\"echo\":22,\"temperature\":20}]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1360,"wires":[["fa50462707e5c385"]]},{"id":"fa50462707e5c385","type":"debug","z":"af25975e21b17ff4","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":1360,"wires":[]}]

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