Let's assume that you have the following object:
jslet erik = { age: 27, location: { city: 'Barcelona', country: 'Spain' } }
If you want to perform a deep destructure of the country
property, then:
jslet { location: { country } } = erik // Equivalent to => let country = erik.location.country console.log(country) // Spain
You could destructure 2 properties at the same time:
jslet { location: { city, country } } = erik // Equivalent to => let country = erik.location.country console.log(city, country) // Barcelona Spain
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.