js unpack array code example
Example 1: unpack array into variables javascript
var yourArr = [1, 2, 3]
[one, , three] = yourArray // 2 is ignored
// one == 1 && three == 3
Example 2: Destructuring Assignment
const HIGH_TEMPERATURES = {
yesterday: 75,
today: 77,
tomorrow: 80
};
//ES6 assignment syntax
const {today, tomorrow} = HIGH_TEMPERATURES;
//ES5 assignment syntax
const today = HIGH_TEMPERATURES.today;
const tomorrow = HIGH_TEMPERATURES.tomorrow;
console.log(today); // 77
console.log(tomorrow); // 80
console.log(yesterday); // "ReferenceError: yesterday is not defined" as it should be.