# 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
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up