Dear reader,
I'm a IT student and I'm pretty new to Node-Red. I would like to merge 2 arrays into 1 using a function.
Here is my flow:
[{"id":"49b7aeb2.4e263","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"7a43b0e4.382d4","type":"html","z":"49b7aeb2.4e263","name":"","property":"payload","outproperty":"payload","tag":"h3.productrow__title.heading.mb-4.mt-3.mt-md-0","ret":"text","as":"single","x":1040,"y":900,"wires":[["47252756.aeff48"]]},{"id":"7763ca89.b836a4","type":"html","z":"49b7aeb2.4e263","name":"","property":"payload","outproperty":"payload","tag":"span.js-price","ret":"text","as":"single","x":1030,"y":980,"wires":[["eee4ea67.097098"]]},{"id":"9abd892f.a12e08","type":"sqlite","z":"49b7aeb2.4e263","mydb":"bc3f4a1b.b28ee8","sqlquery":"msg.topic","sql":"","name":"","x":1270,"y":160,"wires":[["81bc716d.0bda2"]]},{"id":"47252756.aeff48","type":"join","z":"49b7aeb2.4e263","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"payload","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":930,"y":580,"wires":[["81bc716d.0bda2","befb27b2.7df558"]]},{"id":"eee4ea67.097098","type":"function","z":"49b7aeb2.4e263","name":"","func":"var ar = [];\nfor(var i = 1; i < msg.payload.length; i += 2) { // take every second element\n ar.push(msg.payload[i]);\n msg.test = ar\n}\nmsg.payload = msg.test\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":780,"y":740,"wires":[["47252756.aeff48"]]},{"id":"befb27b2.7df558","type":"function","z":"49b7aeb2.4e263","name":"","func":"var myArray = msg.payload;\nvar myArray2 = msg.payload[1];\nmsg.topic = `INSERT INTO alarmsysteem (ArtikelNaam,Prijs) VALUES (\"${myArray.join('\"),(\"')}\")`\nvar topic2 = `(\"${myArray2.join('\"),(\"')}\")`\nvar arrayLength = msg.payload.length;\nfor (var i = 0; i <= arrayLength; i++) {\nmsg.testant = arrayLength\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":200,"wires":[["81bc716d.0bda2"]]},{"id":"81bc716d.0bda2","type":"debug","z":"49b7aeb2.4e263","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1080,"y":460,"wires":[]},{"id":"ac54a326.7b805","type":"http request","z":"49b7aeb2.4e263","name":"Request 5MP PoC camera's","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://www.alarmsysteemexpert.nl/nl/hd-camerabewaking/hikvision-turbo-hd-camerabewaking/dome-camera/power-over-coax-poc-cameras/5mp-poc-cameras/","tls":"","persist":false,"proxy":"","authType":"","x":520,"y":1020,"wires":[["7a43b0e4.382d4","7763ca89.b836a4"]]},{"id":"66807acb.21f1b4","type":"inject","z":"49b7aeb2.4e263","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":1020,"wires":[["ac54a326.7b805"]]},{"id":"bc3f4a1b.b28ee8","type":"sqlitedb","db":"C:\\sqlite\\alarmsysteemexpert.db","mode":"RW"}]
I'm a new user so I cannot upload any files to clarify my question
Anyway I am curious if someone could help me out?
Kind regards,
Gino