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}

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay