Skip to content

Instantly share code, notes, and snippets.

@jhnlsn
Last active February 17, 2018 02:05
Show Gist options
  • Save jhnlsn/5410328221720a724aef65e34b7e9a10 to your computer and use it in GitHub Desktop.
Save jhnlsn/5410328221720a724aef65e34b7e9a10 to your computer and use it in GitHub Desktop.
deep clone doesn't work
const a = [1,2,3,4,5];
const aCloned = [...a];
aCloned.push(7);
console.log(a);
console.log(aCloned);
ref = {big: 'name'};
skills = ["javascript"]
const o = { name: "john", lastname: "nelson", skills: skills, total: {first: ref} };
const oCloned = { ...o };
ref.big = "what"
o.skills.push('php')
oCloned.rancher = true;
console.log(o);
console.log(oCloned);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment