Evangelos Kolimitras Posted on May 3, 2019 How to destructure a variable nested inside an object's array? https://thepracticaldev.s3.amazonaws.com/i/yhyl6hjezy5ctrjqzetm.png Top comments (1) Subscribe Collapse Expand Monica Macomber Monica Macomber Monica Macomber Follow JavaScript, mostly React nowadays Location USA Education Always learning Work Front-End Developer Joined Oct 4, 2019 • Dec 5 '19 Dropdown menu Copy link Hide 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. Code of Conduct • Report abuse For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
If you want to destructure BUILDING to get room2, you could do this:
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.