I want to map the key of one array to another nested array. Both arrays have the same length.
Before:
const idListToInsert = [{ idToInsert: 1 }, { idToInsert: 3 }, { idToInsert: 4 }];
const otherObjectList = [
[{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }],
[{ id: 5 }, { id: 6 }, { id: 7 }],
[{ id: 8 }, { id: 9 }],
];
Target:
const targetList = [
[
{ id: 1, idToInsert: 1 },
{ id: 2, idToInsert: 1 },
{ id: 3, idToInsert: 1 },
{ id: 4, idToInsert: 1 },
],
[
{ id: 5, idToInsert: 3 },
{ id: 6, idToInsert: 3 },
{ id: 7, idToInsert: 3 },
],
[
{ id: 8, idToInsert: 4 },
{ id: 9, idToInsert: 4 },
],
];
I'm having a bit of a hard time finding the starting point for this problem, especially because of the nested structure of the second array.
I am thankful for each hint.