Merge Array of Objects by Property using Lodash

后端 未结 7 1672
北恋
北恋 2020-12-01 06:25

I have two arrays of objects that represent email addresses that have a label and a value:

var original = [
  {
    label: \'private\',
    value: \'private@         


        
7条回答
  •  时光取名叫无心
    2020-12-01 06:46

    Here is another way to merge two objects using Lodash:

    let a = [{
        content: 'aaa',
        name: 'bbb2'
      },
      {
        content: 'aad',
        name: 'ccd'
      }
    ];
    
    let b = [{
        content: 'aaa',
        name: 'bbb'
      },
      {
        content: 'aad1',
        name: 'ccd1'
      }
    ];
    
    let c = [...a, ...b];
    
    let d = _.uniq(c, function(data) {
      return data.content;
    })
    
    console.log(d);

提交回复
热议问题