es6解构赋值
2020-03-29 本文已影响0人
大胡子111
数组
普通:
let [ZS, LS, WW] = [30, 35, 40]
// ZS = 30
// LS = 35
// WW = 40
剩余:
let [ZS, ...LS] = [30, 35, 40]
// ZS = 30
// LS = [35,40]
字符串:
let arr = [ZS,LS,WW,TS] = "hell"
// ZS = "h"
// LS = "E" ...
对象
普通:
let obj = { detail: '123', detail22: '345' }
let { detail, detail22 } = obj
// detail = '123'
// detail22 = '345'
// ...
剩余:
let obj = { detail: '123', detail22: '345', detail33: '888' }
let { detail, ...all } = obj
// detail = '123'
// all = {detail22: '345' ,detail33:'888' }
// ...