Skip to content

Instantly share code, notes, and snippets.

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

// newDroid is a new variable created using rest operator
const { colors, ...newDroid } = droid

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

// the newDroid object is created without the colors attribute
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