Rashmi Vishwakarma Rashmi Vishwakarma - 2 years ago 80
Javascript Question

How to access key from nested object in javascript

Can you please help me how can I access "name" key from obj3. Please find below example.

I am looking for good approch, I dont want to do :


var obj = {
obj1 : {
obj2: {
obj3: {
name: 'jhon'


Answer Source

You could theoretically destructure using es6 for example

const {obj1: {obj2: { obj3: {name: b}}}} = obj console.log(b) //jhon

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download