I'm trying to filter an array using the method from this post, but I can't seem to get it working. My setup is below, which I'm expecting to result in an empty array because the one object in the array matches the filter criteria, but it is resulting in the original array being returned in the console. Is there something here that I'm missing?
var myArr = [
{
link_source_id: "act_0",
link_source_name: "Hello World!",
link_target_id: "obj_1",
link_target_name: "Document",
link_type: "activity-object-input"
}
]
var myFilter = {
link_source_id: "act_0",
link_target_id: "obj_1"
}
myArr = myArr.filter(function (item) {
for (var key in myFilter) {
if (
item[key] === undefined ||
item[key] !== myFilter[key]
)
return false;
}
return true;
});
console.log(myArr)