Created
September 12, 2022 21:12
-
-
Save michael-lynch/a2d4b061c7d0c9bed802927d37da36d0 to your computer and use it in GitHub Desktop.
Deep merge objects
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
| 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