Hello dear Stackoverflow Community
I have encouraged some strange behavior when using splice on my array. I splice the array "tempFilterdProduts" but also the array "this.products" seems to be affected. As a console.log shows the array "this.products" is getting shorter. Is there anything I'm missing here? Any help would be much appreciated! I'm using Angular 12
let tempFilterdProduts = this.products
let itemsToDelete: number[] = [];
let tempCategoryFilterList: number[] = []
this.allCategoriesCheckBox.forEach(ategoriesCheckBox => {
if (!ategoriesCheckBox.checked) {
tempCategoryFilterList.push(ategoriesCheckBox.id);
}
});
let index: number = 0;
tempFilterdProduts.forEach(fProduct => {
if(tempCategoryFilterList.includes(fProduct.CategegoryId)){
itemsToDelete.push(index);
}
index++;
});
for(var i = itemsToDelete.length-1; i >= 0; i--){
tempFilterdProduts.splice(itemsToDelete[i], 1);
}
this.filterdProduts = tempFilterdProduts;
}