1.数组的解构赋值
let [a, b, c] = [1, 2, 3];
console.log(a, b, c);
输出结果 1,2,3
let [a, b, c] = [, 123, ];
console.log(a, b, c);
输出结果 undefined,123,undefined
let [a = 123, b, c] = [, 456, ];
console.log(a, b, c);
输出结果 123,456,undefined
2. 对象的解构赋值
// let {
// name,
// age
// } = {
// name: '刘志恒',
// age: 18
// };
// console.log(name, age);
3.对象属性别名,如果有了别名,原属性名失效
let {
name: na,
age
} = {
name: '刘志恒',
age: 18
};
console.log(na, age);
3.1对象属性别名,申明别名的同时赋值
let {
name: na = "wang",
age
} = {
name: '刘志恒',
age: 18
};
console.log(na, age);
4.Math对象解构
let {
sin,
random
} = Math;
console.log(typeof sin);
console.log(typeof random);
5. 字符串的结构
let [a, b, c, d] = "heng";
console.log(a, b, c, d);
6.字符串的长度
let {
length
} = "liu";
console.log(length);
console.log("heng".length);