I have following array, that I need to transform before inserting into database. Right now my data are looking like this:
And I would like to save the data in this format:
So far I have tried this code, but with no luck:
const buildTvTimeline = (r: Data) =>
{
const meta = get(r, ["meta", "tv"], []);
return Object.keys(meta).map((index: any) =>
{
const game = meta[index].game;
const tile = meta[index].tile;
const dates = meta[index].dates;
const data = dates.map((r: any) => ({ ...r, tile: tile, game: game }));
return data;
});
}
const timeline = buildTvTimeline(r);
const data = Object.keys(timeline).map((index) =>
{
return timeline[index];
});
set(r, ["timeline", "tv"], data);
Any ideas what can I do to transform the format of the first array into the format of the second array?
Thank you in advance