Skip to main content Accessibility Feedback

Extract & Copy Properties

Array Destructuring

A way to extract variables from array properties.

Define an array of variables, and the destructuring syntax will pull the values at the matching indexes out and assign them to the variables.

let lunch = ['turkey sandwich', 'soda', 'chips', 'cookie'];

let [entree, drink, side, desert] = lunch;

// logs "turkey sandwich"
console.log(entree);

// logs "chips"
console.log(side);

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.