Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
70 views
in Technique[技术] by (71.8m points)

javascript - How to remove an object from array in my Vue Project


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...