I have an object
const complicatedObject = {
propertyA: {
property1: 1,
property2: 2
},
propertyB: {
property1: 1,
property2: 2
}
}
If I want to grab propertyA I do
const { propertyA } = complicatedObject
console.log(propertyA) // { property1: 1, property2: 2}
If I want to grab propertyA's property1 value I do
const { propertyA: { property1 } } = complicatedObject
console.log(property1) // 1
I can grab propertyA and propertyA's property1 this way.
const {
propertyA,
propertyA: {
property1
}
} = complicatedObject
console.log(propertyA) // { property1: 1, property2: 2}
console.log(property1) // 1
Is there a simpler way to get both propertyA and property1?
I read the following but I felt like nothing jumped out to me as being the answer.
- https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/
- http://exploringjs.com/es6/ch_destructuring.html#sec_more-obj-destructuring
Thanks!