Skip to content

Instantly share code, notes, and snippets.

@michael-lynch
Created September 12, 2022 21:12
Show Gist options
  • Select an option

  • Save michael-lynch/a2d4b061c7d0c9bed802927d37da36d0 to your computer and use it in GitHub Desktop.

Select an option

Save michael-lynch/a2d4b061c7d0c9bed802927d37da36d0 to your computer and use it in GitHub Desktop.
Deep merge objects
export const merge = (current, updates) => {
for (const key of Object.keys(updates)) {
if (!current.hasOwnProperty(key) || typeof updates[key] !== 'object') {
current[key] = updates[key];
} else {
merge(current[key], updates[key]);
}
}
return current;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment