JavaScript Destructuring
JS
What is destructuring?
Destructuring is a feature in JavaScript (introduced in ES6) that lets you unpack values from arrays or properties from objects into distinct variables.
- It makes your code shorter and cleaner.
Example 1: Array destructuring
javascript CopyEdit
You can also skip elements:
Example 2: Object destructuring
You can also give them new variable names:
Function parameters with destructuring
Very handy for functions:
- Destructuring lets you extract values from arrays or objects into individual variables in a quick, elegant way.