Merge Array of Objects by Property using Lodash Merge Array of Objects by Property using Lodash arrays arrays

Merge Array of Objects by Property using Lodash


_.unionBy():
This method is like _.union except that it accepts iteratee which is invoked for each element of each arrays to generate the criterion by which uniqueness is computed. Result values are chosen from the first array in which the value occurs.

var original = [  { label: 'private', value: 'private@johndoe.com' },  { label: 'work', value: 'work@johndoe.com' }];var update = [  { label: 'private', value: 'me@johndoe.com' },  { label: 'school', value: 'schol@johndoe.com' }];var result = _.unionBy(update, original, "label");console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>