currData = {
id: "iStyle1",
status: "PENDING"
};
data = [
{
id: "splitStyle1",
rows: [
{
id: "1cUMlNRSapc5T",
row: 2,
sequence: 2,
status: "ACTIVE",
assetType: {
id: "iStyle1",
name: "Style"
}
}
]
},
{
id: "splitStyle2",
rows: [
{
id: "1cUMlNRSapc5T",
row: 2,
sequence: 2,
status: "ACTIVE",
assetType: {
id: "iStyle1",
name: "Style"
}
},
{
id: "1cUMlNRSapc5T",
row: 2,
sequence: 2,
status: "ACTIVE",
assetType: {
id: "iStyle2",
name: "Style"
}
}
]
},
{
id: "splitStyle3",
rows: []
},
{
id: "splitStyle4",
rows: []
}
];
I attempted to utilize this information:
const result = this.data.flatMap(item => item.rows.filter((assetType: any) => assetType.id === this.currData.id));
however, it resulted in an empty array. and
const result = this.data.filter((x: any) => x.rows.some((rows: any) => x.rows.filter((y: any) => y)));
console.log(result)
it fails to exclude the iStyle2, and I aim to eliminate the iStyle2 from the rows. Only the data containing iStyle2 in the rows should be displayed.
The desired output should be:
[
{
id: "splitStyle1",
rows: [
{
id: "1cUMlNRSapc5T",
row: 2,
sequence: 2,
status: "ACTIVE",
assetType: {
id: "iStyle1",
name: "Style"
}
}
]
},{
id: "splitStyle2",
rows: [
{
id: "1cUMlNRSapc5T",
row: 2,
sequence: 2,
status: "ACTIVE",
assetType: {
id: "iStyle1",
name: "Style"
}
}
]
}
]
Find the code here: https://stackblitz.com/edit/angular-owuavn?file=src/app/app.component.ts.