It's convenient to extract properties from Object
s by destructuring:
let o = {id: "100", name: "Jane Doe", address: {id:1, city:"Fargo"}},
key = "address";
let {address: {id: id}} = o; // 1
Destructuring patterns can be computed as well:
let {[key]: {city: city}} = o; // Fargo
But it seems apparently not possible to extract properties of nested objects dynamically:
key = "address.city";
({[key]: city} = o); // undefined
Is it possible to destructure nested Object
s with computed patterns?