JavaScript in 60 Seconds

Data Types: Object

An object is similar to an array. The primary difference is that where an array uses numbers as the index, an object uses a unique word. Key:value pairs

let person1 = {age: 13}; // We can retrieve this via 2 methods: person1.age; // -> 13 person1['age']; // ->13 // Like an array you can store any data type in the value. // the key needs to be a string let person1 = {age: 13, name: "Adam", city: "Omaha", pets: ['cat', 'dog', 'fish']}; // you can also nest objects let family = { firstChild: { age: 13, name: "Adam", city: "Omaha", pets: ['cat', 'dog', 'fish'] }, secondChild: { age: 31, name: "Joe", city: "Denver", pets: [] } }; // retrieval of a nested item family.secondChild.city; // -> "Denver"