Destructuring assignment
What is destructuring assignment
To quickly get the values we need in the arrays and objects
is to separate the corresponding key values into the arrays and objects we want to destructure the structure
and then assign them
Deconstruction assignment is divided into
- Array destructuring assignment
- Object destructuring assignment
Basic usage of destructuring assignment
let [name ,age,sex] = [ '张三',22,'男']
console.log(name)
console.log(age)
console.log(sex)
Array destructuring assignment
let [a,[b,[c,d]]] = [1,[2,[3,4]]];
a = 3
console.log(a) // 这边输出的是3
Object destructuring assignment
const a = {
name:"外下羊",
age:12,
}
a.age = 13
console.log(a.age)