Might be duplicate, but I couldn't find it. So I have two arrays of objects:
var a = [{id: '1', name: 'bob'}, {id: '2', name: 'bill'}]
$scope.b = [{id: '4', name: 'jack'}, {id: '2', name: 'bill'}, {id: '1', name: 'bob'}, {id: '3', name: 'john'}]
I want to remove all the a elements from b. I have tried:
$scope.b = $scope.b.filter(function(item){
return a.indexOf(item) === -1;
});
unfortunately, for some reason, the index is always -1, so nothing gets deleted. with some console.log-s
console.log(item);
console.log(a);
console.log(a.indexOf(item));
, this is how the data looks like:
Resource {id: 4, name: "jack"}
[Resource, Resource, Resource, Resource, $promise: Promise, $resolved: true]
-1
indexOfis looking for a reference to the same object - they're not. Do you want to delete byid? or perhaps only whenidandnamematch?