Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Created April 18, 2018 09:31
Show Gist options
  • Save gladchinda/4863a5784f0d9ecc2065caf9d17dcea8 to your computer and use it in GitHub Desktop.
Save gladchinda/4863a5784f0d9ecc2065caf9d17dcea8 to your computer and use it in GitHub Desktop.
const person = {
name: 'John Doe',
age: 25,
location: {
country: 'Canada',
city: 'Vancouver',
coordinates: [49.2827, -123.1207]
}
}
// Observe how mix of object and array destructuring is being used here
// We are assigning 5 variables: name, country, city, lat, lng
const {name, location: {country, city, coordinates: [lat, lng]}} = person;
console.log(`I am ${name} from ${city}, ${country}. Latitude(${lat}), Longitude(${lng})`);
// I am John Doe from Vancouver, Canada. Latitude(49.2827), Longitude(-123.1207)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment