# Use data from 2 arrays

**URL:** <https://discourse.nodered.org/t/use-data-from-2-arrays/30627>\
**Category:** General\
**Created:** [23 July 2020 18:33 UTC](https://discourse.nodered.org/t/use-data-from-2-arrays/30627 "2020-07-23T18:33:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marct](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@marct](https://discourse.nodered.org/u/marct)\
**Post date:** [23 July 2020 18:33 UTC](https://discourse.nodered.org/t/use-data-from-2-arrays/30627/1 "2020-07-23T18:33:25Z")

</div>

Hi,

I am building a flow to extract dates for emptying garbage bins in our street from a website.  
The type of garbage and the date are entered in two separate arrays.

How can I combine those two and read the right date for the type of garbage from the array?

Current flow:

 ![Knipsel1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/1/e124747d25f2c90c9845212781be5007a7e71d1d.jpeg)

```auto
[{"id":"eb8f35dd.1ccf98","type":"tab","label":"Afval kalender","disabled":false,"info":""},{"id":"f925e67a.9d9528","type":"inject","z":"eb8f35dd.1ccf98","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":140,"wires":[["a5a21a6e.18b198"]]},{"id":"a5a21a6e.18b198","type":"http request","z":"eb8f35dd.1ccf98","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://www.radhw.nl/inwoners/ophaalschema?p=3261+PH&h=1","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":140,"wires":[["214bae89.ea7942","c2217819.1b9898"]]},{"id":"214bae89.ea7942","type":"html","z":"eb8f35dd.1ccf98","name":"","property":"payload","outproperty":"payload","tag":".datum","ret":"html","as":"single","x":450,"y":140,"wires":[["50c48c70.76cf24"]]},{"id":"c2217819.1b9898","type":"html","z":"eb8f35dd.1ccf98","name":"soort","property":"payload","outproperty":"payload","tag":".soortafval*","ret":"text","as":"single","x":450,"y":240,"wires":[["b535724d.5ac1e"]]},{"id":"f43f7092.7f421","type":"join","z":"eb8f35dd.1ccf98","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"soort","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":710,"y":180,"wires":[["d4f48ef2.33287"]]},{"id":"d4f48ef2.33287","type":"debug","z":"eb8f35dd.1ccf98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":850,"y":80,"wires":[]},{"id":"b535724d.5ac1e","type":"function","z":"eb8f35dd.1ccf98","name":"part 1","func":"msg.parts = {};\nmsg.parts.id = 12345;\nmsg.parts.index = 0;\nmsg.parts.count = 2;\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":240,"wires":[["f43f7092.7f421"]]},{"id":"50c48c70.76cf24","type":"function","z":"eb8f35dd.1ccf98","name":"part 2","func":"msg.parts = {};\nmsg.parts.id = 12345;\nmsg.parts.index = 1;\nmsg.parts.count = 2;\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":140,"wires":[["f43f7092.7f421"]]}]

```

Output:  
 ![Knipsel2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae241b4d352cd91366fe45bd12dffb13522989cc.jpeg)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 July 2020 18:36 UTC](https://discourse.nodered.org/t/use-data-from-2-arrays/30627/2 "2020-07-23T18:36:51Z")

</div>

Hi & welcome to the forum.

In order to make code more readable and importable it is important to post it between two sets of three backticks - ``` - see this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

Please go back and edit your post.

It would be good if you could also post a screen shot for those of us on a mobile (or for those who have zero interest in loading up your flow but might be happy to reply with a solution)

---

<div class="post-metadata">

**Author:** ![marct](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@marct](https://discourse.nodered.org/u/marct)\
**Post date:** [23 July 2020 18:44 UTC](https://discourse.nodered.org/t/use-data-from-2-arrays/30627/3 "2020-07-23T18:44:16Z")

</div>

Hi Steve,

Thanks for the tip.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 July 2020 18:57 UTC](https://discourse.nodered.org/t/use-data-from-2-arrays/30627/4 "2020-07-23T18:57:33Z")

</div>

Much better 🙂

here are a couple of ways (I'm certain there are better ways)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a2ec748c2a9e3b753ba9e2a24c0a5b3de4e2a9b5.png)

```auto
[{"id":"4bf509d4.404e08","type":"inject","z":"284fa9c6.f473c6","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":140,"wires":[["4d6bc65e.554338"]]},{"id":"4d6bc65e.554338","type":"http request","z":"284fa9c6.f473c6","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://www.radhw.nl/inwoners/ophaalschema?p=3261+PH&h=1","tls":"","persist":false,"proxy":"","authType":"","x":270,"y":140,"wires":[["4ceef695.938588","982c0533.ba3e48"]]},{"id":"4ceef695.938588","type":"html","z":"284fa9c6.f473c6","name":"","property":"payload","outproperty":"payload","tag":".datum","ret":"html","as":"single","x":430,"y":140,"wires":[["9d93f167.6386c"]]},{"id":"982c0533.ba3e48","type":"html","z":"284fa9c6.f473c6","name":"soort","property":"payload","outproperty":"payload","tag":".soortafval*","ret":"text","as":"single","x":430,"y":240,"wires":[["2d257e4.03a6a82"]]},{"id":"df902e16.c5dfb","type":"join","z":"284fa9c6.f473c6","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"soort","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":180,"wires":[["7317470f.fc3eb8","82f9eded.60ce2"]]},{"id":"2d257e4.03a6a82","type":"function","z":"284fa9c6.f473c6","name":"part 1","func":"msg.parts = {};\nmsg.parts.id = 12345;\nmsg.parts.index = 0;\nmsg.parts.count = 2;\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":240,"wires":[["df902e16.c5dfb"]]},{"id":"9d93f167.6386c","type":"function","z":"284fa9c6.f473c6","name":"part 2","func":"msg.parts = {};\nmsg.parts.id = 12345;\nmsg.parts.index = 1;\nmsg.parts.count = 2;\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":140,"wires":[["df902e16.c5dfb"]]},{"id":"7317470f.fc3eb8","type":"function","z":"284fa9c6.f473c6","name":"combine as key/val","func":"var names = msg.payload[0];\nvar dates = msg.payload[1];\nvar combined = {};\n\nfor (let i = 0; i < dates.length; i++) {\n combined[dates[i]] = names[i];\n}\n\nmsg.payload = combined\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":120,"wires":[["7d2644d4.85519c"]]},{"id":"82f9eded.60ce2","type":"function","z":"284fa9c6.f473c6","name":"combine as array of objects","func":"var items = msg.payload[1];\nvar dates = msg.payload[0];\nvar combined = [];\n\nfor (let i = 0; i < items.length; i++) {\n let newObj = {\n item: items[i],\n value: dates[i]\n }\n combined.push(newObj)\n}\n\nmsg.payload = combined\nreturn msg;","outputs":1,"noerr":0,"x":900,"y":240,"wires":[["d8f49f2d.655"]]},{"id":"7d2644d4.85519c","type":"debug","z":"284fa9c6.f473c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1110,"y":120,"wires":[]},{"id":"d8f49f2d.655","type":"debug","z":"284fa9c6.f473c6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1110,"y":240,"wires":[]}]

```

EDIT...

as for accessing the path to these items, use the "copy path" button that appears when you hover over a debug value

---

<div class="post-metadata">

**Author:** ![marct](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@marct](https://discourse.nodered.org/u/marct)\
**Post date:** [24 July 2020 18:01 UTC](https://discourse.nodered.org/t/use-data-from-2-arrays/30627/5 "2020-07-24T18:01:44Z")

</div>

Hi Steve,

That helped me a lot.  
Thank you for your help.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 August 2020 18:01 UTC](https://discourse.nodered.org/t/use-data-from-2-arrays/30627/6 "2020-08-07T18:01:51Z")

</div>

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