const person ={name:'Arif',age:22,job:'we-developer',friendList:['abir','adnan','alvi'],companyDetails:{id:3343,companyName:'IT solution',salary:33400,location:'jahanbarge',}}const[x, y, z]= person.friendList;console.log(x, y, z);//Expected output:abir adnan alvi
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
// 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]}
let options ={title:'My menu',items:['item1','item2']};functionshowMenu({
title ='Untitled',width: w =100,height: h =200,items:[item1, item2]=['something','esle']// default whole array/*
items: [item1 = 'something', item2 = 'else'] // default items
*/}={}/* default empty obj if showMenu() doesn't get an argument */){console.log(`${title}${w}${h}`);console.log(`${item1} and ${item2}`);}showMenu(options);