Destructuring assignment là gì?

Noun Javascript
array destructuring

Cú pháp destructuring assignment là một biểu thức (expression) giúp bạn có thể lấy các giá trị từ mảng (array) hoặc thuộc tính (property) từ các đối tượng (object) thành các biến riêng biệt.


let a, b, rest;
[a, b] = [10, 20];

console.log(a);
// expected output: 10

console.log(b);
// expected output: 20

[a, b, ...rest] = [10, 20, 30, 40, 50];

console.log(rest);
// expected output: Array [30,40,50]

Learning English Everyday