Если я вас правильно понял, это был бы хороший вариант использования метода уменьшения массива, например:
const cards = [
{
id: 1,
details: [
{id:1},
{id:2}
],
sheet:{
id:1
}
},
{
id:2,
details: [
{id:3},
{id:4}
],
sheet:{
id:1
}
},
{
id:3,
details: [
{id:5},
{id:6}
],
sheet:{
id:2
}
}
];
const sheets = cards.reduce( (sheets: Array<any>, card: any) => {
const existingSheet = sheets.find(sheet => card.sheet.id === sheet.id);
if (existingSheet) {
existingSheet.details.concat(card.details);
} else {
sheets.push({id: card.sheet.id, details: card.details});
}
return sheets;
}, []
);
console.log(sheets);