DEV Community

Thabitha Kavyu
Thabitha Kavyu

Posted on

Destructuring an object

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

Top comments (1)

Collapse
 
tabithakavyu profile image
Thabitha Kavyu

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

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