JavaScript - merge two arrays of objects and de-duplicate based on property value

后端 未结 11 1522
渐次进展
渐次进展 2021-02-03 14:36

I want to update (replace) the objects in my array with the objects in another array. Each object has the same structure. e.g.

var origArr = [
          


        
11条回答
  •  梦谈多话
    2021-02-03 15:11

    Here's a solution using underscore:

    var result = _.map(origArr, function(orig){
        return _.extend(orig, _.findWhere(updatingArr, {name: orig.name}));
    });
    

提交回复
热议问题