object解构赋值

let options = {
  title: 'menu',
  width: 100,
  height: 200
}
//如果简写,变量名必须和属性名一致
let {title,width,height} = options
console.log(title,width,height)
let {title:title2,width,height} = options
console.log(title2,width,height)

let {title, ...last} = options
console.log(title,last)

//嵌套对象
let options = {
  size: {
    width:100,
    height:200
  },
  items:['he','ee'],
  extra: true
}
let {size:{width,height},items:[item1],extra} = options
console.log(width,height,item1,extra)

猜你喜欢

转载自www.cnblogs.com/qjb2404/p/12210744.html