lodash icon indicating copy to clipboard operation
lodash copied to clipboard

Intersection and union two arrays by key

Open n1ks0N opened this issue 1 month ago • 2 comments

I have two arrays with objects:

const arr1 = [{ id: 1, paramA: 'value1' }, { id: 2, paramA: 'value2' }];
const arr2 = [{ id: 2, paramB: 'value11' }, { id: 3, paramB: 'value22' }];

Want something like that:

const res = combine(arr1, arr2, 'id');

And expect intersection of two arrays:

res = [{ id: 2, paramA: 'value2', paramB: 'value11' }];

Same questions: https://stackoverflow.com/questions/38612972/how-to-merge-two-arrays-of-objects-by-id-using-lodash https://stackoverflow.com/questions/38505448/how-to-merge-multiple-array-of-object-by-id-in-javascript

I miss this method in lodash. I would find it very useful.

n1ks0N avatar Nov 10 '25 19:11 n1ks0N

I’d like to work on this issue to implement a utility to merge arrays of objects by a key. I can create a PR that handles intersections and merging of properties. Could you please assign this issue to me?

KirtiGautam620 avatar Nov 16 '25 18:11 KirtiGautam620

@KirtiGautam620 no, issues are never assigned in open source - but separately, this doesn't have a "help wanted" label, so it's not yet decided to accept it.

ljharb avatar Nov 16 '25 23:11 ljharb