const user ={name:'Chris',age:33,username:'DailyDevTips',address:{country:'South Africa',postalCode:'7700',},};const{address:{ country },}= user;console.log(country);// South Africa
const user ={name:'Chris',age:33,username:'DailyDevTips',address:{country:'South Africa',postalCode:'7700',},};const{address:{ country },}= user;console.log(country);// South Africa
const user ={name:'Chris',age:33,username:'DailyDevTips',address:{country:'South Africa',postalCode:'7700',},};const{address:{ country },}= user;console.log(country);// South Africa
const user ={name:'Chris',age:33,username:'DailyDevTips',address:{country:'South Africa',postalCode:'7700',},};const{address:{ country },}= user;console.log(country);// South Africa
const user ={name:'Chris',age:33,username:'DailyDevTips',address:{country:'South Africa',postalCode:'7700',},};const{address:{ country },}= user;console.log(country);// South Africa
const user ={name:'Chris',age:33,username:'DailyDevTips',address:{country:'South Africa',postalCode:'7700',},};const{address:{ country },}= user;console.log(country);// South Africa
// Destructuring an object > array > object structureconst returnedObject ={docsArray:[{socketRoom:'',routes:[]},{socketRoom:'',routes:[]},{socketRoom:'',routes:[]},]}// this will destructure the first and second elements from docsArray, and spread the remainderconst{docsArray:[element0, element1,...remainder]}= returnedObject
// taking this further with destructing properties from element0 const{docsArray:[{socketRoom0, routes0}= element0,{socketRoom1, routes1}= element1]}= returnedObject
// note the syntax for destructing Objects and Arraysconst{propName}=Objectconst[element0, element1]=Array// then one layer deep where Object[propName] is an Arrayconst{propName:[element0]}=Object// then two layers, where element0 is an Objectconst{propName:[{propName}= element0]}// three layersconst{propName:[{propName:[element00]}= element0]}
const person ={id:0133,name:"Robert",positon:"web-developer",salary:8000,pColor:"red",pSports:"football",pMovies:["word war 1","destroy the world","long way","Where is my home"],pChild:{firstChild:"Adiba",secondChild:"Alvi"}}const{ secondChild }= person.pChild;console.log(secondChild);//Output: Alvi