Using variables in an array

In my function-Node I have to construct the following msg.payload. I am able to use a variable for the id as well for the value of "Fieldname" but I can't figure out how or if I am able to use a variable to describe the path

msg.payload = [{
    id: iVar,
    fields : { "CAN-THIS-BE-A-VARIABLE-?" : tVar }
}];

Thank you for any help in advance!

This is the best I can do to get what I want working.

Just wanting to check I'm not missing any elephants.

[{"id":"d72327bb.0bc37","type":"string","z":"65c9b63cb09879a0","name":"0","methods":[{"name":"chompLeft","params":[{"type":"str","value":"rgb"}]},{"name":"delLeftMost","params":[{"type":"str","value":","}]},{"name":"delLeftMost","params":[{"type":"str","value":","}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2810,"y":220,"wires":[["ee603826871cfe95","fcfb52c09951a8be"]]},{"id":"33f88dd62e9a1854","type":"string","z":"65c9b63cb09879a0","name":"","methods":[{"name":"delLeftMost","params":[{"type":"str","value":"rgb,"}]},{"name":"left","params":[{"type":"num","value":"1"}]},{"name":"toInteger","params":[]}],"prop":"payload","propout":"pointer","object":"msg","objectout":"msg","x":2770,"y":160,"wires":[["9e72ba1e6e745ccf","d72327bb.0bc37"]]},{"id":"ee603826871cfe95","type":"function","z":"65c9b63cb09879a0","name":"","func":"let pointer = msg.pointer;\n\n\nflow.set(\"test[\"+pointer+\"]\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2980,"y":220,"wires":[[]]},{"id":"fcfb52c09951a8be","type":"debug","z":"65c9b63cb09879a0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2980,"y":260,"wires":[]},{"id":"349b67738dfc8261","type":"inject","z":"65c9b63cb09879a0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,4,0,0,0","payloadType":"str","x":2610,"y":160,"wires":[["33f88dd62e9a1854"]]},{"id":"0a2b7173df8196ef","type":"inject","z":"65c9b63cb09879a0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,2,0,0,0","payloadType":"str","x":2610,"y":120,"wires":[["33f88dd62e9a1854"]]},{"id":"9e72ba1e6e745ccf","type":"debug","z":"65c9b63cb09879a0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"pointer","targetType":"msg","statusVal":"payload","statusType":"auto","x":2960,"y":160,"wires":[]}]

Ok sry to spam the forum I think I got it by trying random stuff xD ... apprently you have to enclose it to brackets [var]

msg.payload = [{
    id: iVar,
    fields : { [fVar] : tVar }
}];

Hope it helps someone

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