ECMAScript question detail
Destructuring
Destructuring is a javascript expression for extracting multiple values from data stored in objects(properties of an object) and Arrays.
Object destructuring:
This feature is used to extract values from an object.
const user = { firstName: 'John', lastName: 'Kary' };
const {firstName, lastName} = user;
console.log(firstName, lastName); // John, Kary
Array destructuring:
This feature is used to extract values from an array.
const [one, two, three] = ['one', 'two', 'three'];
console.log(one, two, three); // one, two, three
You can use destructing in below places,
- Variable declarations
- Assignments
- Parameter definitions
- for-of loop