Skip to content

Instantly share code, notes, and snippets.

@oxechicao
Created September 16, 2024 15:00
Show Gist options
  • Save oxechicao/a4c385eb1e26a4bcf961f3bed006a14f to your computer and use it in GitHub Desktop.
Save oxechicao/a4c385eb1e26a4bcf961f3bed006a14f to your computer and use it in GitHub Desktop.
Cloning objects recursively
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