Created
September 16, 2024 15:00
-
-
Save oxechicao/a4c385eb1e26a4bcf961f3bed006a14f to your computer and use it in GitHub Desktop.
Cloning objects recursively
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 clone(oldObject) { | |
const newObject = {}; | |
for (const key in oldObject) { | |
if (typeof oldObject[key] === 'object') { | |
newObject[key] = clone(oldObject[key]); | |
continue; | |
} | |
newObject[key] = oldObject[key]; | |
} | |
return newObject; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment