📌  相关文章
📜  按 id 从数组中删除对象 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:27.295000             🧑  作者: Mango

代码示例1
//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);        
}