Easily extract array elements or objects properties
store them in variables
- Array Destructuring
[a, b] = ['Hello', 'Max];
conosle.log(a); //Hello
console.log(b); //Max
const numbers = [1, 2, 3];
[num1, num2] = numbers;
console.log(num1, num2); //1, 2
[num1, , num3] = numbers;
console.log(num1, num3)l //1, 3
- Object Destructuring
{name} = {name:'Max', age:28};
console.log(name) // Max
console.log(age) //undefined
'TIL' 카테고리의 다른 글
Primitive Type과 Reference Type (0) | 2020.08.04 |
---|---|
Spread & Rest Operator (0) | 2020.08.04 |
let과 const (feat. var) --정리 현재진행형 (0) | 2020.08.03 |
String.prototype.split() (0) | 2020.07.20 |
array 비우기 (0) | 2020.07.20 |