need an help I’ve two array which I needed to filte
const arr1 = [
{
"id": "processType",
"name": "Conceptual Target State Process Model",
"display_name": "Conceptual Target State Process Model",
"checked": true
},
{
"id": "processType",
"name": "Current State Process Map",
"display_name": "Current State Process Map",
"checked": true
},
{
"id": "processSubType",
"name": "Current State Process Model",
"display_name": "Current State Process Model",
"checked": true
},
{
"id": "processSubType",
"name": "Current State Process Model (MCA)",
"display_name": "Current State Process Model (MCA)",
"checked": true
}
]
const arr2 = [
{
"id": "processType",
"name": "Current State Process Map",
"display_name": "Current State Process Map",
"checked": true
}
]
const filteredElements = arr1.filter(function(obj) {
return !arr2.some(function(obj2) {
return obj.name === obj2.name;
// ^ ^
});
});
console.log(filteredElements);
My expected output is
[
{ id: "processType", name: "Current State Process Map", display_name: "Current State Process Map", checked: true
},
{ id: "processSubType", name: "Current State Process Model", display_name: "Current State Process Model", checked: true
},
{ id: "processSubType", name: "Current State Process Model (MCA)", display_name: "Current State Process Model (MCA)", checked: true
}
]
Not sure what’s going wrong, I need to filter based on id & name
I’m filtering arr1 and using some checking for the name.