ES6嵌套对象的解构
有下列对象需要解构:
const obj:any[] = [
{
id: 33,
username: "mengsongna",
realName: "孟松娜",
company: {
id: 1,
company_name: "海思特"
},
role: {
id: 4,
role_name: "业务管理员",
role_value: "saler"
},
email: ""
}
]
解构方式为:
const [{role}] = obj;
console.log(role) // { id: 4, role_name: '业务管理员', role_value: 'saler' }