How to extract deeply nested property in JavaScript(ES6)?
Gulshan Saini
June 29, 2020
1 min

Accessing nested object properties in JavaScript used to be a huge pain using the dot notation. However, things got easier in ES6 with the introduction of destructuring assignments.

Let’s say we have the following complex object and we want to get the value of property company that is under the ad property. The old way of doing this is to use the dot notation data.ad.company

In ES6 there is a better and simpler way of extracting the nested objects. To extract the value of company we could simply write

Next, we can just log the value to see the result

We could even rename(alias) the company property to organization while destructuring as follows

That’s where ES6 destructuring gets more powerful.


Previous Article
How to delete a property from a JavaScript object?

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to Get Current Date in Human Readable Form in JavaScript?
October 03, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media