I am trying to filter array of objects on the basis of some conditions. If I apply single condition it works but if I applied some more condition it doesn't worked!!. I don't understand why its not working for multiple conditions.Below is my code.
const removeItemIfConditationMatch = () => {
let filter = [];
filter = arr.filter(
item => item.id !== myObj.id &&
item.level !== myObj.level &&
item.technology !== myObj.technology &&
item.type !== myObj.type)
console.log(filter)
}
let myObj = {
"questions": [],
"technology": "Can_Js",
"type": "NON_CODE",
"level": "EASY",
"id": 0
}
let arr = [{
"questions": [],
"technology": "Can_Js",
"type": "NON_CODE",
"level": "EASY",
"id": 0
},
{
"questions": [],
"technology": "Network_Simulator",
"type": "NON_CODE",
"level": "EASY",
"id": 1
},
{
"questions": [],
"technology": "Java",
"type": "NON_CODE",
"level": "HIGH",
"id": 0
},
{
"questions": [],
"technology": "Java",
"type": "CODE",
"level": "HIGH",
"id": 1
},
{
"questions": [],
"technology": "React Js",
"type": "NON_CODE",
"level": "MEDIUM",
"id": 1
}
]
removeItemIfConditationMatch()
In the above code if I filter on single condition it works but if you run above code it won't work. Anyone have any idea why Its not working where I am doing wrong. Any help will be appreciated.
After applying my multi filter criteria I am expecting below result.
[
{
"questions": [],
"technology": "Network_Simulator",
"type": "NON_CODE",
"level": "EASY",
"id": 1
},
{
"questions": [],
"technology": "Java",
"type": "NON_CODE",
"level": "HIGH",
"id": 0
},
{
"questions": [],
"technology": "Java",
"type": "CODE",
"level": "HIGH",
"id": 1
},
{
"questions": [],
"technology": "React Js",
"type": "NON_CODE",
"level": "MEDIUM",
"id": 1
}
]
In short I am expecting if my condition match then remove that Object from array list.