var a = [
{
name: "a",
child: [{
name: "bb",
limit: 12
},
{
name: "ss",
limit: 12
}
]
},
{
name: "b",
child: [{
name: "ss",
limit: 12
},
{
name: "kk",
limit: 12
}
]
},
{
name: "c",
child: [{
name: "aa",
limit: 12
},
{
name: "mm",
limit: 12
}
]
},
{
name: "d",
child: [{
name: "aa",
limit: 12
},
{
name: "mm",
limit: 12
}
]
}
];
var b = [
{
name: "b",
child: [{
name: "ss"
},{
name:"kk"
}]
},
{
name: "a",
child: [{
name: "ss"
}]
}
];
var c = [];
a.forEach(function(e) {
b.forEach(function(i) {
if(e.name == i.name) {
e.child.forEach(function(j, index1) {
i.child.forEach(function(k, index2) {
if(j.name !== k.name) {
e.child.splice(index1,1);
console.log(e.child)
}
})
})
c.push(e);
};
})
});
console.log(c)
I want to find out all the things in a that are the same as b name, and why do I find out that they are like this