# Join two times same array, how?

**URL:** <https://discourse.nodered.org/t/join-two-times-same-array-how/69754>\
**Category:** General\
**Tags:** function-node\
**Created:** [29 October 2022 02:47 UTC](https://discourse.nodered.org/t/join-two-times-same-array-how/69754 "2022-10-29T02:47:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexandrechoske](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexandrechoske/32/69851_2.png) [@alexandrechoske](https://discourse.nodered.org/u/alexandrechoske)\
**Post date:** [29 October 2022 02:47 UTC](https://discourse.nodered.org/t/join-two-times-same-array-how/69754/1 "2022-10-29T02:47:50Z")

</div>

Hi guys, I am facing a hard time here with array and need some help.

Basically what I am trying to do is to join 2 arrays, but here is a little bit more complicated because I have 2 ids on arr2, and the id in arr1.

Example:

arr1 I have the "id" and I need the "name" value.

arr2 I have "time\_a" and "time\_b", wich are 2 unique ids.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/dba13b1fd24519a3e21b860a56eb732593987bde.png)

the challenge here is: How to join 2 times and bring the "name" from arr1 FOR "time\_a" and "time\_b"

I have done the 1 time join already and it looked like this.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/5/450f1eb78af756afd23750a1290de0cb950bb3d1.png)

```auto
msg.teamsTbl = global.get('teamsTbl')
msg.matchesTbl = global.get('matchesTbl')
  
let arr1 = msg.teamsTbl
let arr2 = msg.matchesTbl
  
let merged = [];
  
for (let i = 0; i < arr1.length; i++) {
    merged.push({
        ...arr1[i],
        ...(arr2.find((itmInner) => itmInner.time_a === arr1[i].id))
    }
    );
}
msg.merged_a = merged
  
global.set('merged_a',msg.merged_a)
  
return msg;

```

Now I need to do another join, bringing the id again, but getting stuck.

Any Ideas? Thanks!

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [29 October 2022 05:07 UTC](https://discourse.nodered.org/t/join-two-times-same-array-how/69754/2 "2022-10-29T05:07:11Z")

</div>

Can you post a _short_ example of both incoming arrays and the expected output ?

---

<div class="post-metadata">

**Author:** ![alexandrechoske](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexandrechoske/32/69851_2.png) [@alexandrechoske](https://discourse.nodered.org/u/alexandrechoske)\
**Post date:** [29 October 2022 12:49 UTC](https://discourse.nodered.org/t/join-two-times-same-array-how/69754/3 "2022-10-29T12:49:49Z")

</div>

Sure, im limited to post pics, but I'll try my best hahha

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8e5214c1e14b8b67ba73d55496841b1a531bb89.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b8f506828153aa3500e24bc0445244c0c609e8d0.png)

I hope my explanation is better now, thanks!

---

<div class="post-metadata">

**Author:** ![alexandrechoske](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexandrechoske/32/69851_2.png) [@alexandrechoske](https://discourse.nodered.org/u/alexandrechoske)\
**Post date:** [30 October 2022 16:18 UTC](https://discourse.nodered.org/t/join-two-times-same-array-how/69754/4 "2022-10-30T16:18:37Z")

</div>

I managed to do it, renaming the "id" "abrv" and "name" column to their respective name + \_A

and I re-joined the arrays renaming another results to their respective names + \_B

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f75d0e0ace8c61b67a2cb48b4ad6bede6b7fd6c.png)

---

<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:** [13 November 2022 16:19 UTC](https://discourse.nodered.org/t/join-two-times-same-array-how/69754/5 "2022-11-13T16:19:15Z")

</div>

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