Advertisement
Beginner JavaScript, Destructuring, Spread & Rest

How do you destructure properties out of an object?

Short answer

Object destructuring pulls named properties into variables using curly-brace syntax; the variable names must match the property names unless you rename them.

Save JavaScript mock interview
Advertisement
AModel answer
Object destructuring pulls named properties into variables using curly-brace syntax; the variable names must match the property names unless you rename them.
const user = { name: 'Sam', age: 30 };
const { name, age } = user;
console.log(name); // 'Sam'
Real-world example
Extracting just the fields you need from a large API response object.
Likely follow-ups
  • How do you rename a destructured variable?
Related topics