I've got an object msg.payload[0] and I now want to add another element to the array i.e I want to create msg.payload[1] as well
I can't get how to do this into my head
I'm doing this in Blockly but if someone could show me what to do in JavaScript I'll hopefully be able to transcode it
E1cid
2
In javascript you could Push an element.
msg.payload.push({"prop":1})
oh dear - don't think I've got that in Blockly
I'm thinking that maybe I get the [0] value - save it temp - then delete obj - recreate it with 2 elements and repopulate [0]
E1cid
4
Or
let index = msg.payload.count
msg.payload[index] = {"prop":1}
I'll try that
Unfortunately got bigger problems - my Blockly code has just vanished on me!
But flows.json.backup has saved me
Worked out what to do
Just create an empty list
then add first Object to it
then add second Object to it
then set msg.payload to the list
Dead simple
PS Blocky has a insert at end of list block which is converted to a push
I'ts been 6 months since I last touched JS