Skip to content

Instantly share code, notes, and snippets.

@chsami
Created June 25, 2018 15:49
Show Gist options
  • Save chsami/7bf92ecdb018f816f2f5cd95b40c1916 to your computer and use it in GitHub Desktop.
Save chsami/7bf92ecdb018f816f2f5cd95b40c1916 to your computer and use it in GitHub Desktop.
deepCopyExample() {
let product = {
name: 'beef',
price: 10,
category: {
name: 'food',
type: 'meat'
}
};
let deepCopyOfProduct = JSON.parse(JSON.stringify(product));
console.log('[deepCopy] value before edit: ' + product.name);
deepCopyOfProduct.name = 'Ross beef';
console.log('[deepCopy] value after edit: ' + product.name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment