I have two arrays of objects that represent email addresses that have a label and a value:
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: 'schhol@johndoe.com'
}
];
Now I want to compare and merge the two arrays by the label
field, so that the result would look like this:
var result = [
{
label: 'private',
value: 'me@johndoe.com'
},
{
label: 'work',
value: 'work@johndoe.com'
},
{
label: 'school',
value: 'schol@johndoe.com'
}
]
How can I do this e.g. using lodash?
See Question&Answers more detail:os