Skip to content

Instantly share code, notes, and snippets.

@peeke
Last active February 11, 2022 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peeke/5c04191cdee4da6cd3d6cff14f2caedd to your computer and use it in GitHub Desktop.
Save peeke/5c04191cdee4da6cd3d6cff14f2caedd to your computer and use it in GitHub Desktop.
Deep merge two javascript objects
function merge(target, source) {
if (!(target instanceof Object) || !(source instanceof Object)) return source
return Object.entries(source).reduce(
(result, [key, value]) => ({
...result,
[key]: merge(result[key], value)
}),
{ ...target }
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment