DEV Community

Sujith V S
Sujith V S

Posted on

3 2

Destructuring in JavaScript | ES6

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
Enter fullscreen mode Exit fullscreen mode

Array destructuring

//Object destructuring
const myFriends = {
    friend1:'Nivedh',
    friend2:'Vibin',
    friend3:'Joel'
}
const {friend2, friend1} = myFriends
console.log(friend1, friend2)

Output:
Nivedh Vibin
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay