Kelly Selden
Kelly Selden

Reputation: 1276

object destructuring: how to use intermediate nested property

var { iWantThis: { andThis, andThisToo } } = x;

Is there a way to get access to all three in one destructuring call? I want to avoid two calls like so:

var { iWantThis } = x;
var { andThis, andThisToo } = iWantThis;

Upvotes: 8

Views: 510

Answers (1)

locks
locks

Reputation: 6577

The closest I can come up with is:

var { iWantThis, iWantThis: { andThis, andThisToo } } = x;

Though I'd use let instead, if I'm using ES6 ;)

Upvotes: 10

Related Questions