user7922494
user7922494

Reputation:

js destruct a sub-object inner object

I assign a object:

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'

how to I get sub-object location.province by deconstruct???

Upvotes: 0

Views: 837

Answers (1)

Felix Kling
Felix Kling

Reputation: 816324

By doing "nested" destructuring:

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

For such questions, always look at MDN first because it usually has many examples.

Upvotes: 1

Related Questions