var array = [{id :1, name :"test1"},{id :2, name :"test2"},{id :2, name :"test2"},{id :3, name :"test3"},{id :4, name :"test4"}];
var anotherOne = [{id :2, name :"test2"}, {id :4, name :"test4"}];
var filteredArray = array.filter(function(array_el){
return anotherOne.filter(function(anotherOne_el){
return anotherOne_el.id == array_el.id;
}).length == 0
});
This code remove all "id:2" object. Like do this:
{id :1, name :"test1"},{id :3, name :"test3"}
But I want remove only one of same object. Like this:
{id :1, name :"test1"},{id :2, name :"test2"},{id :3, name :"test3"}
But If anotherOne of array have two same object, need two remove.