DEV Community

Thabitha Kavyu
Thabitha Kavyu

Posted on

Destructuring an object

const Baby = {
  name: 'Tabby',
  favColor: 'brown',
  Age: 21
const {name, } = Baby;
console.log(name); // 'Tabby'
Enter fullscreen mode Exit fullscreen mode

Discussion (1)

tabithakavyu profile image
Thabitha Kavyu Author

Using the rest operator ..., you can store all remaining properties from the original object to a variable.

   const { name,}= Baby;
   console.log(rest); // 
  {favColor: "Tabby", Age: 21}