Skip to content

Instantly share code, notes, and snippets.

@splincode
Last active April 30, 2019 19:10
Show Gist options
  • Select an option

  • Save splincode/bd6dc43e3e1a04122b8ad4041764f12c to your computer and use it in GitHub Desktop.

Select an option

Save splincode/bd6dc43e3e1a04122b8ad4041764f12c to your computer and use it in GitHub Desktop.
function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj)); // serialize -> deserialize -> unique clone
}
const original = {
a: undefined,
b: { c: undefined },
d: () => undefined
};
// JSON does not have an undefined value. Use null instead of undefined.
const deepCopy = { ...deepCopy(original), e: null }; // { b: { }, e: null }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment