Created
April 28, 2020 21:15
-
-
Save sandrabosk/f41a7f9ec17b0133a4fe248810893a3d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ************************************************ | |
// *********** Mixed destructuring **************** | |
// ************************************************ | |
const customer = { | |
name: { | |
firstName: 'ivan', | |
lastName: 'zoro' | |
}, | |
age: 32, | |
preferences: [ | |
{ | |
tech: ['cameras', 'smartwatches'], | |
books: ['science fiction', 'coding'] | |
} | |
] | |
}; | |
const { | |
name: { firstName, lastName }, | |
age, | |
preferences: [{ tech, books }] | |
} = customer; | |
console.log(firstName, lastName, age); // ==> 'ivan' 'zoro' 32 | |
console.log(tech, books); // ==> [ 'cameras', 'smartwatches' ] [ 'science fiction', 'coding' ] | |
// comment out the previous when demo the next: | |
const { | |
name: { firstName, lastName }, | |
age, | |
preferences: [{ tech: technology, books: literature }] | |
} = customer; | |
console.log(firstName, lastName, age); // ==> 'ivan' 'zoro' 32 | |
console.log(technology, literature); // ==> [ 'cameras', 'smartwatches' ] [ 'science fiction', 'coding' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment