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

后端 未结 11 1528
渐次进展
渐次进展 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 14:53

    I came here looking for exactly this, saw @Gruff Bunny 's technique and wondered if 'lodash' wouldn't perhaps be a superior option even to 'underscore'?

    Lo and behold :

    let result = _.unionBy(updatingArr, origArr, 'name');
    

提交回复
热议问题