Object destructuring is an approach to access an object's properties. We use object destructuring because it dries our code by removing duplication.const
band={
bandName:"Led",
famousSong:"stairway to heaven",
year:1996,
anotherFamousSong:"JKSABSA",
};
const{bandName,famousSong}=band;
const {bandName:var1,famousSong:var2,...restProps}=band;
console.log(restProps);
Object Destructuring of array objects.
const users=[
{userId:1,firstName:'Jeevika',gender:'female'},
{userId:2,firstName:'aastha',gender:'female'},
{userId:3,firstName:'Jaaz',gender:'male'}
]
console.log(users);
const [user1,user2,user3]=users;
const[{firstName},,{gender}]=users;
const[{firstName:userfirstn},,{gender:user3g}]=users;
const[{firstName:userfirstn,userId:id},,{gender:user3g}]=users;
console.log(userfirstn,user3g,id);
for(let user of users){
console.log(users);
console.log(user.firstName);
}