Then the array would need to be an array of objects, so you could define both "A" and "aaa". You would add the topic to the output in the code.
[{"id":"045bc0047a0505c0","type":"inject","z":"452103ea51141731","name":"every 3 seconds","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"payload\":\"A\",\"topic\":\"aaa\"},{\"payload\":\"B\",\"topic\":\"bbb\"},{\"payload\":\"C\",\"topic\":\"ccc\"}]","payloadType":"json","x":190,"y":880,"wires":[["f2e806626ac988d7"]]},{"id":"f2e806626ac988d7","type":"function","z":"452103ea51141731","name":"function 13","func":"msg.payload.forEach((obj, index) => {\n let output = [null,null,null];\n output[index] = {payload: obj.payload,topic: obj.topic}; \n setTimeout(() => {\n node.send(output)\n }, (index*1000))\n \n})\nreturn null;","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":880,"wires":[["5f0762fc37e816eb"],["5f0762fc37e816eb"],["5f0762fc37e816eb"]]},{"id":"5f0762fc37e816eb","type":"debug","z":"452103ea51141731","name":"debug 96","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":720,"y":740,"wires":[]}]
[edit] re-reading your question if you have ["aaa","bbb","ccc"]
in msg.topic
and ["A"."B","C"]
in msg.payload
, then you could add the topic with.
msg.payload.forEach((num, index) => {
let output = [null,null,null];
output[index] = {payload: num,topic: msg.topic[index]};
setTimeout(() => {
node.send(output)
}, (index*1000))
})
return null;