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 Personal Trusted User Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss 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 Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm 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.