I want to remove an element from an array based on its any property that can be its key, name or email or something else it can be.
Html
<tr *ngFor="let person of persons;" (click)="remove(person.key)">
<td>{{person.key}}</td>
<td>{{person.name}}</td>
<td>{{person.email}}</td>
</tr>
typescript
persons = [
{ key: 1, name: 'Mr.sohail', email: '[email protected]' },
{ key: 2, name: 'Mr.Farhan', email: '[email protected]' },
{ key: 3, name: 'Mr.Fida', email: '[email protected]' },
{ key: 4, name: 'Mr.Liaqat', email: '[email protected]' },
{ key: 5, name: 'Mr.Abdullah', email: '[email protected]' },
{ key: 6, name: 'Mr.Ubaid', email: '[email protected]' },
{ key: 7, name: 'Mr.Wasif', email: '[email protected]' }
]
remove method to remove an element based on key property but it removes based on index.
remove(key) {
console.log(key);
this.data.persons.splice(key, 1);
}
Please let me know the required changes to apply
Thanks
keyis unique property of element. Still I'm wondering, what wrong you see with this answer..