2017-09-21 2 views
0

assigner un objet:js destruct un sous-objet objet interne

const info = { name: 'Peter', location: { province: 1, city: 2 } }; 
let { name } = info; 
console.log(name); // 'Peter' 

// then how to get location.province 
let { 'location.province': province } = info; 
console.log(province); // 'undefined' 

comment j'obtenir location.province sous-objet par déconstruire ???

+0

'' 'let {province} = info.location;' '' – Wainage

+0

@Wainage merci, peut-être un peu mieux –

Répondre

1

En faisant "emboîtés" destructuration:

let {name, location: {province}} = info; 

Pour ces questions, toujours regarder d'abord parce qu'il MDN habituellement has many examples.

+0

oh, merci, je suis négligent !!! –