need an help I’ve two array which I needed to filter
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
}
]
I tried my way but getting wrong result
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
Urvashi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.