DEV Community

Evangelos Kolimitras
Evangelos Kolimitras

Posted on

How to destructure a variable nested inside an object's array?

https://thepracticaldev.s3.amazonaws.com/i/yhyl6hjezy5ctrjqzetm.png

Top comments (1)

Collapse
 
monicat profile image
Monica Macomber

If you want to destructure BUILDING to get room2, you could do this:

const [,,{floor: { rooms: { room2 }}}] = Building;

The first two commas skip over the first two objects inside your array. Then you just destructure objects until you get to the value you want to use.