Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (13.1k points)

Can anyone help me how I can able to remove an object from an array in JavaScript? The object looks like:


name = "serdar";

1 Answer

0 votes
by (26.7k points)

In able to remove the object, you can use the splice keyword:

var arr = [{id:1,name:'serdar'}];


// []

Below is an example you can look:

var arr = [{id:1,name:'serdar'}, {id:2,name:'alfalfa'},{id:3,name:'joe'}];

removeByAttr(arr, 'id', 1);   

// [{id:2,name:'alfalfa'}, {id:3,name:'joe'}]

removeByAttr(arr, 'name', 'joe');

// [{id:2,name:'alfalfa'}]

I hope this will help.

Want to become a Java expert? join Java Certification now!!

Related questions

0 votes
0 answers
0 votes
1 answer
asked Jan 27, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer

Browse Categories