ES6多层解构

const info = {
  person: {
    name: 'xiaobe',
    other: {
      age: 22,
    }
  },
  song: 'rolling',
}

// 解构person的内容
const { person: { name, other: { age } } } = info;

// 解构song
const { song } = info;

但请注意, personother是属于未定义的变量code

参考ES6很是棒的特性-解构blog

相关文章
相关标签/搜索