17. Creating your own objects


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-9Sgpi/3/4?curriculum_id=506324b3a7dffd00020bf661

This code works, but not the way I want it to... instead of logging each key on it's own line, I get 9 lines of undefined. This typically means that the key has no defined value. Which means it thinks I want it to log the key value of i 9 times. But I just want to loop through all 9 keys in myOwnObject once and print each on its own line. Is there a way to do this, or can you just not loop through the keys of an object?

var myOwnObject = new Object();

myOwnObject.log = function() {
    this.firstName = "Colin";
    this.middleName = "Kelly Siler";
    this.lastName = "Young";
    this.nickName = "Aqua Phoenix";
    this.nickShort = "Aqua";
    this.age = 18;
    this.Name = this.firstName + " " + this.middleName + " " + this.lastName;
    this.Name_v1 = this.firstName + " \"" + this.nickName + "\" " + this.lastName;
    this.Name_v2 = this.firstName + " \"" + this.nickShort + "\" " + this.lastName;
    
    for (i = 0; i < 9; i++) {
        console.log(this.i);
    };
};

myOwnObject.log();

#2

Nevermind, I found a work around by doing something like this:

var myOwnObject = {
    name: "Colin Kelly Siler Young",
    nickName: "Aqua Phoenix",
    age: 18
};

var objectList = [myOwnObject];

var logObject = function(object) {
    console.log("Name: " + object.name);
    console.log("Nickname: " + object.nickName);
    console.log("Age: " + object.age);
};

for (i = 0; i < objectList.length; i++) {
    logObject(objectList[i]);
};

#3