Destructure Object Properties in JavaScript

JavaScript·2 min read·Jan 1, 2025

The destructuring assignment syntax allows you to selectively extract properties from objects and assign them to distinct variables in a concise and structured way.

let { key, ..., keyN } = object;

Note: When destructuring a property that doesn't exist within the object, the specified variable will hold the undefined value.

Example

Let's consider this script:

const bike = {  brand: 'Honda',  model: 'Africa Twin'};const { brand, model } = bike;console.log(brand);console.log(model);

When executed, it will extract the brand and model properties of the bike object into two distinct variables of the same name, and output their values.

Unlock the program 🚀

Pay once, own it forever.

€79

30-day money-back guarantee

  • 13 modules
  • 113 lessons with full-code examples
  • 29 projects with commented solutions
  • All future lesson and project updates
  • Lifetime access

By submitting this form, you agree to the Terms & Conditions and Privacy Policy.