美文网首页
es6解构赋值

es6解构赋值

作者: 大胡子111 | 来源:发表于2020-03-29 23:27 被阅读0次

数组

普通:
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' }
// ...

相关文章

网友评论

      本文标题:es6解构赋值

      本文链接:https://www.haomeiwen.com/subject/qvvpuhtx.html