How to access nested objects in JavaScript?

To access nested objects in JavaScript, use the dot like so: object.subObject.property.

Here's how you do it:

const person = {
  name: 'Sally',
  address: {
    city: {
      name: 'Chicago'
    }
  },
  '401k': {
    bank: {
      name: 'Citi'
    }
  }
};

// Chicago
console.log(person.address.city.name);

// for properties that do not start with a character
// or contain special symbols,
// use this syntax: ['property']

// Citi
console.log(person['401k'].bank.name);