判断两个数组某个属性值是否相同,相同的就把第二个数组的对象全部放入第一个数组。

字数 2阅读 547

如下

var cc=[
{'goodlistId': '1'},
{'goodlistId': '2'}];
var dd=[{Id: 1, goodlistItemId: 1},
{Id: 2, goodlistItemId: 1},
{Id: 3, goodlistItemId: 1},
{Id: 4, goodlistItemId: 1},
{Id: 5, goodlistItemId: 2},
{Id: 6, goodlistItemId: 2},
{Id: 7, goodlistItemId: 2},
{Id: 8, goodlistItemId: 2}];

cc.forEach((n,x)=>{
    var aaa=[];
    dd.forEach((m,y)=>{
        var tt=n.goodlistId.toString()
        var kk=m.goodlistItemId.toString()
        if(tt.indexOf(kk)!=-1){
            aaa.push(m)
            n['xx']=aaa
            console.log('90')
        }
    })
    
   
  })
console.log(cc)

推荐阅读更多精彩内容