解构赋值
# 一行
let people = { name: null, age: null }
let result = { name: 'Margin', age: 16 }(({ name: people.name, age: people.age } = result))
console.log(people) // {name: 'Margin', age: 16}
1
2
3
2
3
# 基础数据类型
const { length: a } = '1234'
console.log(a) // 4
1
2
2
# 数组解构
const arr = [1, 2, 3]
const { 0: first, length, [length - 1]: last } = arr
console.log(first, last, length) //1 3 3
1
2
3
2
3
编辑 (opens new window)
上次更新: 2023/09/17, 23:41:49