Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

angular remove object from array by id

//Remove an object from an array by ID (or by other parameter)
person: Person = { id: 2, name: 'Maria' };
listOfPersons = [
  { id: 1, name: 'Jonas' },
  { id: 2, name: 'Maria' }
];

removePerson(person: Person): void {
  this.listOfPersons = this.listOfPersons.filter(({ id }) => id !== person.id);        
}
 
PREVIOUS NEXT
Tagged: #angular #remove #object #array #id
ADD COMMENT
Topic
Name
3+2 =