JavaScript
x
2
1
var { iWantThis: { andThis, andThisToo } } = x;
2
Is there a way to get access to all three in one destructuring call? I want to avoid two calls like so:
JavaScript
1
3
1
var { iWantThis } = x;
2
var { andThis, andThisToo } = iWantThis;
3
Advertisement
Answer
The closest I can come up with is:
JavaScript
1
2
1
var { iWantThis, iWantThis: { andThis, andThisToo } } = x;
2
Though I’d use let
instead, if I’m using ES6 😉