//解构 可以从数组或对象中提取值并赋给变量
//--- 数组解构
let [x, y] = [1, 2]
console.log("x:", x, "y:", y)
let [, , c] = [10, 20, 30]
console.log("c:", c)
//扩展运算符
let [A, ...B] = [1, 2, 3, 4, 5, 6]
console.log("A:", A, "B:", B)
let [x2, y2 = 200] = [100] //默认值
console.log("x2:", x2, "y2:", y2)
//两数交换
let x3 = 10
let y3 = 20; //不加分号会报错
[x3, y3] = [y3, x3]
console.log("x3:", x3, "y3:", y3)
//--- 对象解构
let person = {
name: '邓瑞',
gender: '男',
web: 'dengruicode.com'
}
let { name } = person
console.log("name:", name)
//重命名
let { name: userName, gender, web } = person
console.log("userName:", userName, "gender:", gender, "web:", web)
//默认值
let { address = "安徽" } = person
console.log("address:", address)
13.解构
-- 未经授权禁止转载 --