Created
September 15, 2019 10:54
-
-
Save ObsidianCat/f2b749c42a99b97db57dea059764ad57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object destructuring | |
//Object | |
const response = { | |
status: 200, | |
data: { | |
user: { | |
name: 'Rachel', | |
title: 'Editor in Chief' | |
}, | |
account: {}, | |
company: 'Smashing Magazine' | |
} | |
} | |
//Destructuring second level properties | |
const { data: {user, company}} = response | |
//console.log(user, company); | |
//with renaming | |
const { data: {user: currentUser}} = response | |
//console.log(currentUser); | |
//with renaming and default values (key does not exist in source) | |
const { data: {location: city = 'New York'}} = response | |
//console.log(city); | |
//Destructuring third level | |
const {data: {user: {name: userName}}} = response | |
//console.log(userName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment