JS ES6 解构赋值

it2025-08-17  6

解构赋值

ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构。

数组的解构赋值

let [a, b] = [1, 2] // a = 1, b = 2 let [a, b, c = 100] = [1, 2]

对象的解构赋值

let {hello, world} = {hello: 1, world: 2} let {hello = 1, world} = {world: 2} let {hello:w, world} = {world: 2}

字符串的结构赋值

函数参数的解构赋值

最新回复(0)