Add example for destructuring nested objects (#24133)

Also changed styling to be more consistent
This commit is contained in:
Oğuzcan Yavuz
2018-12-07 04:27:24 +03:00
committed by Manish Giri
parent fbab448003
commit 172ec835d7

View File

@ -63,6 +63,16 @@ const {first: firstName, last: lastName} = fullName;
console.log(firstName, lastName); // John Smith
```
You can also use Destructuring on nested objects.
```js
const person = {firstName: "John", lastName: "Smith", address: {city: "Istanbul", country: "Turkey"}};
const {address: {city, country}} = person;
console.log(city, country); // Istanbul Turkey
```
**Array Destructuring with rest**
When destructuring an array, you can unpack and assign the remaining part of it to a variable using the rest pattern: