Object Destructuring.

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",

};

//first method for object destructuring
const{bandName,famousSong}=band;
// We can use object destructuring to alias property names incase we do not want to use the original property name.
const {bandName:var1,famousSong:var2,...restProps}=band;
//restProps refers to the other properties of object
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);
// destruct
const [user1,user2,user3]=users;
//to access firstName of object1 and gender of object3
const[{firstName},,{gender}]=users;
//assigning new name to access object
const[{firstName:userfirstn},,{gender:user3g}]=users;
//To get 2 attributes from same object 
const[{firstName:userfirstn,userId:id},,{gender:user3g}]=users;
console.log(userfirstn,user3g,id);
//using for-of loop to access object
for(let user of users){
     console.log(users);
     console.log(user.firstName);
 }