var alldesignationsarr = ['Employee','Manager'];
答案 0 :(得分:0)
您可以使用desgdescarr.filter()
:
var alldesignationsarr = ['Employee','Manager'];
var desgdescarr = [{
"designation": {
"name": "Employee",
"ptest": {}
},
"designation": {
"name": "Manager",
"ptest": {}
},
"designation": {
"name": "Managers",
"ptest": {}
}
}];
var res = desgdescarr.filter((obj) => alldesignationsarr.indexOf(obj.designation.name) === -1);
console.log(res);

如果您想对原始数组进行更改,那么您也可以使用简单的forEach
逻辑:
var alldesignationsarr = ['Employee','Manager'];
var desgdescarr = [{
"designation": {
"name": "Employee",
"ptest": {}
},
"designation": {
"name": "Manager",
"ptest": {}
},
"designation": {
"name": "Managers",
"ptest": {}
}
}];
desgdescarr.forEach((obj, index) => {
if(alldesignationsarr.indexOf(obj.designation.name) !== -1){
desgdescarr.splice(index,1);
}
});
console.log(desgdescarr);