Below is my json object in which I have nested listofdeciosion object. If listofdecisoion length is greater than 1 and it has decision name as 'AEE' then I have to remove that object from listofdecision and if length of decision is 1 and it has decisionname as 'AEE' then remove entire object. My logic is not working for else part
[
{
"anomalyId":49,
"listOfDecision":[
{
"decisionId":69,
"decisionName":"à reprendre",
}
],
"deleted":false
},
{
"anomalyId":51,
"listOfDecision":[
{
"decisionId":71,
"decisionName":"Bride A1 Carter Fan",
}
],
"deleted":false
},
{
"anomalyId":85,
"listOfDecision":[
{
"decisionId":128,
"decisionName":"AEE",
}
],
"deleted":false
},
{
"anomalyId":81,
"listOfDecision":[
{
"decisionId":121,
"decisionName":"AEE",
},
{
"decisionId":123,
"decisionName":"à repeindre",
},
{
"decisionId":122,
"decisionName":"A Retoucher SOUS ITT",
}
],
"deleted":false
},
{
"anomalyId":82,
"listOfDecision":[
{
"decisionId":124,
"decisionName":"AEE",
}
],
"deleted":false
}
]
public hideAEEDecisionRow(res){
//let tempDataSource = [];
this.tempDataSource = [...res];
this.tempDataSource.forEach((item, index) => {
const tempListOfDecision = [...item.listOfDecision];
if (item.listOfDecision.length === 1) {
if (item.listOfDecision[0].decisionName === 'AEE') {
this.tempDataSource.splice(index, 1);
}
} else {
console.log("here in else")
tempListOfDecision.forEach((decision, decisionIndex) => {
if (decision.decisionName === 'AEE') {
tempListOfDecision.splice(decisionIndex, 1);
}
console.log("tempListOfDecision =>",tempListOfDecision)
})
item.listOfDecision = tempListOfDecision;
}
});
this.dataSource = this.tempDataSource;
console.log("tempDataSource =>",this.tempDataSource);
// // call list of decisions method
this.assignListOfdecisionsToAllObjects(this.tempDataSource);
console.log("viewAllDataSource=>",this.viewAllDataSource);
}