How to return the difference of two objects?
$scope.a = [
{name: "Lunchmeat"},
{name: "Apple"},
{name: "Bread"},
{name: "Milk"},
{name: "Mustard"},
{name: "Cheese"}
];
$scope.b = [
{name: "Bread"},
{name: "Milk"},
{name: "Mustard"},
{name: "Cheese"}
];
$.grep($scope.a, function (el) {
if ($.inArray($scope.b,el) == -1) console.log(el);//not working
});
The output I'm looking for is Object [{name: "Lunchmeat"},{name: "Apple"}] as this is the difference.
Can anyone help please?