Skip to content

Instantly share code, notes, and snippets.

@arnotes
Last active February 8, 2021 23:04
Show Gist options
  • Save arnotes/e802a27f11a4a33feedbdf83a6f4f171 to your computer and use it in GitHub Desktop.
Save arnotes/e802a27f11a4a33feedbdf83a6f4f171 to your computer and use it in GitHub Desktop.
deepMerge
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