Last active
February 8, 2021 23:04
-
-
Save arnotes/e802a27f11a4a33feedbdf83a6f4f171 to your computer and use it in GitHub Desktop.
deepMerge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepMerge(target, source){ | |
const result = {...target,...source}; | |
const keys = Object.keys(result); | |
for(const key of keys){ | |
const tprop = target[key]; | |
const sprop = source[key]; | |
//if two objects are in conflict | |
if(typeof(tprop) == 'object' && typeof(sprop) == 'object'){ | |
result[key] = deepMerge(tprop, sprop); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment