Here's the scenario:
export interface ISchoolsPreview {
// Shared
AgeID: string;
School_name?: string;
}
A Checkbox change triggers a function:
onChange(code: string, name: string, check: boolean): void {
const tempPreview: ISchoolsPreview = {AgeID: code, School_name: name};
if (check) {
this.schoolsPreview.push(tempPreview);
} else {
//This is where I encounter an issue
const index = this.schoolsPreview.indexOf(tempPreview);
if (index > -1) {
this.schoolsPreview.splice(index, 1);
}
}
}
The 'check' variable determines whether to add or remove an element from schoolsPreview based on checkbox status. Adding works fine but when trying to remove, indexOf(tempPreview) always returns -1 even with the same entry passed.
How can I properly delete an element from my Interface List?