Answers for "remove array from object with id"

3

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);        
}
Posted by: Guest on August-19-2021
0

object delete with id filter javascript

const hero = [{'id' : 1, 'name' : 'hero1'}, {'id': 2, 'name' : 'hero2'}];
//remove hero1
const updatedHero = hero.filter(item => item.id !== 1);
Posted by: Guest on January-04-2021

Code answers related to "remove array from object with id"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language