Back to results for “Property Descriptors & Immutability”
JavaScript › Destructuring, Spread & Rest

How do you destructure properties out of an object?

Beginner

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.

Common follow-ups: How do you rename a destructured variable?