Merge two array of objects with same keys, some object won't have the same value?

前端 未结 3 620
广开言路
广开言路 2020-12-21 01:16

I want to merge two arrays of objects. The keys are the same but the values might not always be the same.

Any solution is appreciated preferably in javascript, but

3条回答
  •  萌比男神i
    2020-12-21 01:56

    Here's a Python solution. This modifies g, which you may or may not want.

    c_by_id = {d['id']: d for d in c}
    for item in g:
        item.update(c_by_id.get(item['id']), {})
    

提交回复
热议问题