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.
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.
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!