Tried to delete multiple object from an array by selecting the checkbox table row. But in my code only 1 item is deleted. Not able to delete multiple selection object. How to resolve this issue?
app.component.ts:
removeSelectedRow() {
this.data2.forEach((value, index) => {
console.log(value);
if (value.isSelected === true) {
this.data2.splice(index, 1);
}
});
}
splicewon't work in aforEachloop, since every time you splice, you affect theindexes of the undeleted items (see Why isn't splice working in this for loop?). Instead,reduceorfilteryour array to a new array without the items.