Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created April 28, 2020 21:15
Show Gist options
  • Save sandrabosk/f41a7f9ec17b0133a4fe248810893a3d to your computer and use it in GitHub Desktop.
Save sandrabosk/f41a7f9ec17b0133a4fe248810893a3d to your computer and use it in GitHub Desktop.
// ************************************************
// *********** 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