Skip to content

Instantly share code, notes, and snippets.

@darleykrefta
Created March 20, 2021 13:31
Show Gist options
  • Save darleykrefta/14d98f0373c3123d3103d3f4039a0c13 to your computer and use it in GitHub Desktop.
Save darleykrefta/14d98f0373c3123d3103d3f4039a0c13 to your computer and use it in GitHub Desktop.
const droid = {
  name: 'R2-D2',
  height: '1.08',
  colors: ['blue', 'silver']
}

const newDroid = droid

delete newDroid.colors

//the original object is updated by deleting colors attribute
console.log(droid)
// [object Object] {
//   height: '1.08',
//   name: 'R2-D2'
// }

// newDroid was updated by reference
console.log(newDroid)
// [object Object] {
//   height: '1.08',
//   name: 'R2-D2'
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment