How to remove a particular object from an array?

There is an array of objects:
[{name:'test', lastname: 'test', gender:'f'},{name:'test1', lastname: 'test1', gender:'f'},{name:'test2', lastname: 'test2', gender:'m'}]

you want to remove the next object from the array
{name:'test1', lastname: 'test1', gender:'m'}
How to do it?
July 9th 19 at 10:12
3 answers
July 9th 19 at 10:14
Solution
var data = [{name:'test', lastname: 'test', gender:'f'},{name:'test1', lastname: 'test1', gender:'f'},{name:'test2', lastname: 'test2', gender:'m'}],
 massiv = {name:'test1', lastname: 'test1', gender:'m'};
data.forEach(function(d, index){
 if (d == massiv) {
 data.splice(index, 1)
}
 });
July 9th 19 at 10:16
Solution
var someArray = [{name:'test', lastname: 'test', gender:'f'},{name:'test1', lastname: 'test1', gender:'f'},{name:'test2', lastname: 'test2', gender:'m'}];
$.each(someArray, function(i){
 if(someArray[i].gender === 'm') {
someArray.splice(i,1);
 return false;
}
});
console.log(someArray);

someArray = [{name:'test', lastname: 'test', gender:'f'},{name:'test1', lastname: 'test1', gender:'f'},{name:'test2', lastname: 'test2', gender:'m'}];
johnRemoved = someArray
 .filter(function (el) {
 return el.gender !== "m";
}
);
console.log(johnRemoved);
July 9th 19 at 10:18
You can:
for(i in a){ 
 if((a[1].name == 'test1') && (a[1].lastname == 'test1') && (a[1].gender == 'm')) delete a[i]; 
}

Find more questions by tags JavaScript