access deep nested elements in array of objects in javascript

// Access deep nested elements in array of objects in JavaScript

// Create an array of objects
var data = [
  {
    name: 'Alice',
    age: 25,
    address: {
      city: 'New York',
      zip: 10001
    }
  },
  {
    name: 'Bob',
    age: 30,
    address: {
      city: 'San Francisco',
      zip: 94107
    }
  }
];

// Access the city of the first object
var firstCity = data[0].address.city;

// Access the zip of the second object
var secondZip = data[1].address.zip;