I have an array, which contains a list of names. If those names match a key/value pair in another array, I'd like to remove the object containing the match and return the array without that object.
Here's what I have so far as an example:
var supervisorsToRemove = ["Supervisor1", "Supervisor2"];
var data = [{id: "Name1", supervisor: "Supervisor1"},{id: "Name2", supervisor: "Supervisor1"},{id: "Name3", supervisor: "Supervisor2"},{id: "Name4", supervisor: "Supervisor3"}]
I'd like the resulting data array to be:
data = [{id: "Name4", supervisor: "Supervisor3"}]
I can remove one supervisor's objects with the following:
var supervisorsToRemove = "Supervisor1";
data = $.grep(data, function(e){
return e.supervisor != supervisorsToRemove;
});
But when I try to remove all in the array, it doesn't work:
var supervisorsToRemove = ["Supervisor1","Supervisor2"];
data = $.grep(data, function(e){
return e.supervisor != supervisorsToRemove;
});