Destructuring is used to extract the array elements or object properties and store them in variables.
See the example below,
Object destructuring
//Array destructuring
const number = [1, 2, 3];
const [num1, , num3] = number
console.log(num1, num3)
Output:
1 3
Array destructuring
//Object destructuring
const myFriends = {
friend1:'Nivedh',
friend2:'Vibin',
friend3:'Joel'
}
const {friend2, friend1} = myFriends
console.log(friend1, friend2)
Output:
Nivedh Vibin
Top comments (0)