Skip to content

Instantly share code, notes, and snippets.

@jniac
Created May 28, 2020 21:49
Show Gist options
  • Select an option

  • Save jniac/27b0f3374c6ec270f27b68ce573cc0a7 to your computer and use it in GitHub Desktop.

Select an option

Save jniac/27b0f3374c6ec270f27b68ce573cc0a7 to your computer and use it in GitHub Desktop.
function deepClone(target) {
if (!target || typeof target !== 'object')
return target
const clone = Array.isArray(target) ? [] : {}
for (const [key, value] of Object.entries(target)) {
clone[key] = deepClone(value)
}
return clone
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment