unpacking array javascript code example
Example 1: unpack array into variables javascript
var yourArr = [1, 2, 3]
[one, , three] = yourArray
Example 2: destructuring objects
({ a, b } = { a: 10, b: 20 });
console.log(a);
console.log(b);
({a, b, ...rest} = {a: 10, b: 20, c: 30, d: 40});
console.log(a);
console.log(b);
console.log(rest);
Example 3: destructuring assignment
Destructuring assignment is special syntax introduced in ES6,
for neatly assigning values taken directly from an object.
const user = { name: 'John Doe', age: 34 };
const { name, age } = user;
Example 4: javascript destructing
const x = [1, 2, 3, 4, 5]
const [a, b] = x
console.log(a)
console.log(b)