Skip to content

Instantly share code, notes, and snippets.

@morajabi
Created June 22, 2017 13:27
Show Gist options
  • Save morajabi/c10169d49c78598b33eb8cc4fa5b2596 to your computer and use it in GitHub Desktop.
Save morajabi/c10169d49c78598b33eb8cc4fa5b2596 to your computer and use it in GitHub Desktop.
Cloning objects in javascript with Object.assign({}, src)
console.group("Cloning objects");
const firstObject = {
name: 'Mohammad',
};
const clonedObject = Object.assign({}, firstObject);
console.log(
firstObject,
'is cloned like this',
clonedObject,
`and the result of first === clone is ${firstObject === clonedObject}`
);
console.groupEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment