Convenient Syntax
Destructuring allows you to " unpack " arrays and objects into variables in a single line.
1. Arrays
let [firstName, surname] = "Ilya Kantor".split(' ');
alert(firstName); // Ilya
2. Objects
let options = { title: "Menu", width: 100 };
let { title, width } = options;
alert(title); // "Menu"
Default Values
let { title, height = 200 } = options;
// If height is not in the object, 200 will be used.
Tip
You can use the spread operator ... to collect the " rest " into a separate variable:
let [name1, ...rest] = ["Julius", "Caesar", "Consul"];
// rest is an array ["Caesar", "Consul"]