angular remove object from array by id

Solutions on MaxInterview for angular remove object from array by id by the best coders in the world

showing results for - "angular remove object from array by id"
Wissem
19 May 2020
1//Remove an object from an array by ID (or by other parameter)
2person: Person = { id: 2, name: 'Maria' };
3listOfPersons = [
4  { id: 1, name: 'Jonas' },
5  { id: 2, name: 'Maria' }
6];
7
8removePerson(person: Person): void {
9  this.listOfPersons = this.listOfPersons.filter(({ id }) => id !== person.id);        
10}