This is my current data structure
{
key1: [
{
a: 123,
b: 100,
c: 300,
start_date: “05-01-2021”
},
{
a: 123,
b: 100,
c: 300,
start_date: “06-01-2021”
},
{
a: 123,
b: 100,
c: 300,
start_date: “07-01-2021”
}
],
key2: [
{
a: 123,
b: 100,
start_date: “05-01-2021”
},
{
a: 123,
b: 100,
start_date: “06-01-2021”
},
{
a: 123,
b: 100,
start_date: “07-01-2021”
}
]
}
Each object in the array has a key-value pair called start_date
, which I am trying to match on.
Basically, I’m trying to each element in key1 that matches the start_time with each element in key2, and it can be for N number of key1 - keyN
I’ve tried some solutions with reduce, and running it through a loop, but I’m trying to find a elegant solution that doesn’t have me creating for loops.
The end result I want is:
{
key1: [
{
a: 123,
b: 100,
c: 300,
start_date: “05-01-2021”
},
{
a: 123,
b: 100,
c: 300,
start_date: “06-01-2021”
},
{
a: 123,
b: 100,
c: 300,
start_date: “07-01-2021”
}
],
key2: [
{
a: 123,
b: 100,
start_date: “05-01-2021”
},
{
a: 123,
b: 100,
start_date: “06-01-2021”
},
{
a: 123,
b: 100,
start_date: “07-01-2021”
}
],
key3: [
{
a: 246,
b: 200,
c: 300,
start_date: “05-01-2021”
},
{
a: 246,
b: 200,
c: 300,
start_date: “06-01-2021”
},
{
a: 246,
b: 200,
c: 300,
start_date: “07-01-2021”
}
]
}
All arrays will always be the same length.