Answers for "how to merge 2 object array by the same key with lodash"

0

how to merge 2 object array by the same key with lodash

Lodash
var a = [
  { userId:"p1", item:1},
  { userId:"p2", item:2},
  { userId:"p3", item:4}
];

var b = [
  { userId:"p1", profile:1},
  { userId:"p2", profile:2},
  { userId:"p4", profile:4}
];
var merged = _.merge(_.keyBy(a, 'userId'), _.keyBy(b, 'userId'));
var values = _.values(merged);
console.log(values);
<script src="https://cdnjs.cloudflare.com/ajax/libs/
Posted by: Guest on June-26-2020

Code answers related to "how to merge 2 object array by the same key with lodash"

Code answers related to "Javascript"

Browse Popular Code Answers by Language