2 回答
TA贡献1847条经验 获得超11个赞
您只需与 结合.filter使用.some,例如:
let d = {
"designProjects": [
{
"projectNumber": "number1",
"name": "test1"
},
{
"projectNumber": "number2",
"name": "test2"
},
{
"projectNumber": "number3",
"name": "test3"
},
]
}
let a = {
"allProjects": [
{
"project": {
"name": "test1",
"number": "number1"
},
"employee": {
"displayName": "name1"
},
"projectRoleName": "Editor"
},
{
"project": {
"name": "test2",
"number": "number2"
},
"employee": {
"displayName": "name2"
},
"projectRoleName": "Editor"
},
]
};
console.log(
d.designProjects.filter((designProject) => {
return !a.allProjects.some((project) => designProject.projectNumber === project.project.number && designProject.name === project.project.name);
})
);
TA贡献1880条经验 获得超4个赞
filter
用于根据条件返回一个新的过滤数组
some
将成为条件并在找到匹配项后立即返回
const designProjects = [{
"projectNumber": "number1",
"name": "test1"
},
{
"projectNumber": "number2",
"name": "test2"
},
{
"projectNumber": "number3",
"name": "test3"
},
];
const allProjects = [{
"project": {
"name": "test1",
"number": "number1"
},
"employee": {
"displayName": "name1"
},
"projectRoleName": "Editor"
},
{
"project": {
"name": "test2",
"number": "number2"
},
"employee": {
"displayName": "name2"
},
"projectRoleName": "Editor"
},
]
const cleaned = designProjects.filter((x) => {
return !allProjects.some(y => y.project.number === x.projectNumber);
});
console.info(cleaned);
添加回答
举报