I have two arrays, derived from scraping a web page.
eg ["Sydney", "Perth"]
and [24, 33]
I need to join them to create an array of objects based on the topic and array element number
[{"location": "Sydney", "temperature": 24}, {"location": "Perth", "temperature": 33}]
[{"id":"6195c4d9beec1f9f","type":"inject","z":"864d3d22d52ad621","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temperature","payload":"[24, 33]","payloadType":"json","x":150,"y":220,"wires":[["02fd63ee1b69d3f9"]]},{"id":"e065d4d1e7c0eb23","type":"inject","z":"864d3d22d52ad621","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"location","payload":"[\"Sydney\", \"Perth\"]","payloadType":"json","x":170,"y":180,"wires":[["02fd63ee1b69d3f9"]]},{"id":"02fd63ee1b69d3f9","type":"join","z":"864d3d22d52ad621","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":410,"y":220,"wires":[["e274243f93ae035d"]]},{"id":"e274243f93ae035d","type":"debug","z":"864d3d22d52ad621","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":220,"wires":[]},{"id":"6b7a839f8188b374","type":"comment","z":"864d3d22d52ad621","name":"How to get [{\"location\": \"Sydney\", \"temperature\": 24},{\"location\": \"Perth\", \"temperature\": 33}]","info":"","x":370,"y":140,"wires":[]}]
I suspect this is a job for the "reduce sequence" mode?
There are some join node example flows but they don't help me here.
Chatgpt suggests a join node and a function but surely it's possible without a function?
[{"id":"1ac1ef8e2d69e5ca","type":"function","z":"864d3d22d52ad621","name":"function 12","func":"let arrA = msg.payload.location;\nlet arrB = msg.payload.temperature;\n\nlet result = [];\n\nfor (let i = 0; i < Math.min(arrA.length, arrB.length); i++) {\n result.push({\n AAA: arrA[i],\n BBB: arrB[i]\n });\n}\n\nmsg.payload = result;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":220,"wires":[["e274243f93ae035d"]]},{"id":"02fd63ee1b69d3f9","type":"join","z":"864d3d22d52ad621","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":370,"y":220,"wires":[["1ac1ef8e2d69e5ca"]]}]