JavaScript Objects

Video

JavaScript Notes

JavaScript
    var dog = {"name":"Woody", "type":"dog"};
    var cat = {"name":"Bob", "type":"cat"}; 
    var petNames = ["Woody", "Bob"];
    var pets = [dog, cat];
    var pets = [{"name":"Woody", "type":"dog"}, cat];   // with object literal

    pets.push({"name":"Roxy", "type":"dog"}); // add another object to top of the array 
    cat.age = 2; //adds the property 'age' to the object 'cat' and sets it to 2
    dog["age"] = 14; //adds the property 'age' to the object 'dog' and sets it to 14
    pets[0].age = 14; //add a new property to the first object of the 'pets' array, called 'age' and set it to 14 
    pets[2]["age"] = 4; //add a new property to the third object of the 'pets' array, called 'age' and set it to 4