I have a scenario where I need to merge two objects and concatenate strings if they have the same key.
obj1 = {
name: 'John',
address: 'Cairo'
}
obj2 = {
num : '1',
address: 'Egypt'
}
After merging, the resulting object should look like this:
merged = {name: "John", num: "1", address: "Cairo, Egypt"}
When using _.defaults(obj1, obj2) or _.merge(obj1, obj2), there's an issue with the address property as it gets overwritten by the value from obj2. Therefore, I'm looking for a way to merge the two objects while concatenating the address properties from each object.