Search⌘ K

Destructuring

Explore how to use JavaScript ES6 destructuring syntax to extract values from objects and arrays efficiently. Learn to assign variables, rename properties, set default values, use the rest operator, and swap variables with ease.

MDN defines destructuring like this:

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

Let’s start with destructuring objects first.

 

Destructuring Objects #

To ...