Skip to content
On this page

js

let test =[1,3]
let [x,y] =test
console.log(x,y)  // 1,3

还可以进行不完全解构

js
let test =[1,3]
let [x] =test
console.log(x) //1

// 还可以用占位符号取得后面值 类似于

let [_,x]= test
console.log(x) //3

事实上,只要某种数据结构具有 Iterator 接口,都可以采用数组形式的解构赋值。

Iterator 接口看这边