Skip to content
sergio edited this page Nov 10, 2020 · 10 revisions

Deconstructing

NOTE how for Objects we use const {} and for arrays const []

const doggie = {
  first: 'Buzz',
  breed: 'Great Pyrenees',
  fur_color: 'black and white',
  activity_level: 'sloth-like',
  favorite_food: 'hot_dogs'
};
 
const { first, breed } = doggie;

and with arrays:

const dogs = ['Great Pyrenees', 'Pug', 'Bull Mastiff']

const [medium, small, giant] = dogs
console.log(medium, small, giant) // Great Pyrenees, Pug, Bull Mastiff

const [, small, giant] = dogs
console.log(small, giant) //  Pug, Bull Mastiff

Clone this wiki locally