/* Object destructuring */ const unicorn = { name: 'pony', age: 3 }; const { name, age } = unicorn; console.log(name); // -> 'pony' console.log(age); // -> 3
// ES5 way var name = unicorn.name; var age = unicorn.age;
// Aliasing const { name: a, age: b } = unicorn console.log(a) // -> 'pony' console.log(b) // -> 3
/* Array destructuring */ const ages = [3, 1, 2]; const [firstAge] = ages; console.log(firstAge); // -> 3
// Skipping elements const [first, , last] = ages; console.log(first); // -> 3 console.log(last); // -> 2
By Michael Kühnel
A short overview about ES6 Object and Array assignment destructuring
Frontend Developer working for Micromata 👨🏼💻