How can I remove an object from an array?
array = [{id:"1", name:"Jhon"},
{id:"2", name:"Kabir"},
{id:"3", name:"Rasel"}];
I want to find the id number and then remove that object. How do i do this?
How can I remove an object from an array?
array = [{id:"1", name:"Jhon"},
{id:"2", name:"Kabir"},
{id:"3", name:"Rasel"}];
I want to find the id number and then remove that object. How do i do this?
array = [{id:"1", name:"Jhon"},
{id:"2", name:"Kabir"},
{id:"3", name:"Rasel"}];
console.log(remove_by_id( array, '2' ));
function remove_by_id( array, id ) {
const index = array.findIndex( el => el.id === id );
if( index !== -1 )
array.splice( index, 1 )
return array;
}