nested object javascript code example

Example 1: accessing nested objects javascript

var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
};
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"

Example 2: nested objects javascript

var backPack = {
  color: 'black',
  straps: 4,
  isHeavy: true,
  wallet: {
	cash: '$10,000',
	creditCards: 6
  }
  tablet: {
	brand: 'Apple iPad',
  	buttons: 1
  }
};

Example 3: how to access nested objects in javascript

var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
};
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"

Example 4: javascript nested objects

Do my eyes decieve me, or is the second answer the same as the first, but
with more upvotes?

Tags:

Css Example