Javascript - removing object from array by key value

前端 未结 4 1476
清歌不尽
清歌不尽 2020-12-20 02:29

I have an array of objects

let people = [{

  Name: \'Bob\',

  Age: \'45\',
},
{
  Name: \'Jim\',

  Age: \'45\',
}

];

let person = people.filter(person =         


        
4条回答
  •  不知归路
    2020-12-20 03:02

    1. Find the index of the object where name = "Bob"
    2. Remove it from the array using splice()

    people.splice(people.findIndex(({Name}) => Name == "Bob"), 1);

提交回复
热议问题