Hey guys I'm trying to remove all objects from an array that matches the values from a second array. Allow me to explain with some examples!
var originalObj = [
{"id":"88","name":"Lets go testing"},
{"id":"88","name":"Have fun boys and girls"},
{"id":"108","name":"You are awesome!"},
{"id":"99","name":"Have fun boys and girls"},
{"id":"108","name":"You are awesome!"},
{"id":"99","name":"Have fun boys and girls2"},
{"id":"108","name":"You are awesome!"}
]
Currently with my javascript code I can only remove ONE specified value from object and any occurrences with said value
var updatedObj= $.grep(originalObj , function(e){
return e.id!= '88';
});
console.log(updatedObj)
[
{"id":"108","name":"You are awesome!"},
{"id":"99","name":"Have fun boys and girls"},
{"id":"108","name":"You are awesome!"},
{"id":"99","name":"Have fun boys and girls2"},
{"id":"108","name":"You are awesome!"}
]
What I want to accomplish is have the .grep function look up a second array that looks something like this.
var filterID = ["88","99"];
so the result should look something like this
//Needs updating
//var updatedObj= $.grep(originalObj , function(e){
// return e.id!= '88'; <-- needs to match all filterID values instead
// });
console.log(updatedObj)
[
{"id":"108","name":"You are awesome!"},
{"id":"108","name":"You are awesome!"},
{"id":"108","name":"You are awesome!"}
]
Any help would be greatly appreciated!
Thank you.