how to access object object in 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: js create object with properties
var mycar = new Car('Eagle', 'Talon TSi', 1993);
Example 3: js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}