I have an array of objects in my javascript application, looks something like
var data = [
{
id:2467,
name:'alex',
grade:'B',
},
{
id:5236,
name:'bob',
grade:'A-',
},
{
id:1784,
name:'carl',
grade:'C',
},
{
id:5841,
name:'dave',
grade:'AA',
},
{
id:3278,
name:'harry',
grade:'B+',
},
]
Now I have to remove or pop an object from this array on the basis of object id, using a function something like
function removeStudent(id){
//logic for removing object based on object id
}
It should be like
removeStudent(5236);
then the data array afterwards should be like
var data = [
{
id:2467,
name:'alex',
grade:'B',
},
{
id:1784,
name:'carl',
grade:'C',
},
{
id:5841,
name:'dave',
grade:'AA',
},
{
id:3278,
name:'harry',
grade:'B+',
},
]
I tried using pop()
but I think that will remove the last element from the array, not the specific one.
I have looked at this post of removing an element from array
How do I remove a particular element from an array in JavaScript?
but I didn't find my answer here respected to objects Needed help!