---
# System prepended metadata

title: Destructure (Destructure Object)

---

# Destructure (Destructure Object)

there are 2 type of destructure
# 1- Destructure object
======= Simple Object ========

const city = {
  name: "Delhi",
  area: 40,
  pincode: 1100
}

======= old way ======== 
 const name = city.name;
 console.log(name);

======= new way ======== 
 const { name } = city;
 console.log(name);
 
 // old
const country = {
  name: "India";
}

======= old way ======== 
let pincode = city.pincode;
let cityPinCode = pincode
if (!pincode) {
  cityPinCode = 110058;
}

======= new way ========
const countryName = country.name;
// const cityName = city.name || '';
// const pincode = city.pincode || 110058;


const { pincode: cityPinCode = 110058 } = city;

const { name: cityName = '', pincode: cityPinCode = 110050 } = city;
console.log(cityPinCode);

#  rename key
when two object have the same properties like name...
 const country = {
   name: "India"
 }
 const city = {
  name: "Delhi",
  area: 40,
  pincode: 1100
}
const { name: cityName } = city;
const { name: countryName } = country;
console.log(cityName, countryName);


# Destructing Arrays

https://www.w3schools.com/REACT/react_es6_destructuring.asp
