title: Using JSON to create instances of an object
body: <p>I'm trying to learn to program. I've gone through a list of tutorials sites online and I'm stuck on a thing that I think is extremely important for me to understand.</p>
  
  <p>My questions:</p>
  
  <ol>
  <li><p><strong>(This is what I'd like to understand most)</strong> In my for...in loop, why is creating new "obj" objects using the "Contacts" constructor working? It seems like I would need a different name each time I loop so that I don't overwrite the object that I've created the pass before. If this is correct, how do I do this if I don't know anything about the number or value of contacts ahead of time? Additionally, why does the title of the any of the objects in the console logs not say obj? Am I confused about what it means to create an instance of an object? Are the names of these instances unimportant?</p></li>
  <li><p>Why are all of the properties undefined? Should referencing properties from the temporary "i" variable work?</p></li>
  </ol>
  
  <p>Creating objects from an unknown total of data entries seems really important. Unfortunately, places like Codecademy fall short here. You always manually create new instances of objects with hardcoded names they give you. But what would happen if there were two of the same name?</p>
  
  <p>Thanks so much for any help I may get on this. Don't hold back from telling me anything else silly that I may be doing.</p>
  
  <p>Here is a link to a console screenshot - <a href="http://i.imgur.com/TK4dtfV.png" rel="nofollow">http://i.imgur.com/TK4dtfV.png</a></p>
  
  <pre><code>var TestApp = {};
  
  // my data... taken from wherever
  TestApp.jsonContacts = {
      contact1: {
          name: "Ethan",
          age: 24
      },
      contact2: {
          name: "Evan",
          age: 30
      },
      contact3: {
          name: "Paul",
          age: 9000
      }
  };
  
  // I know this is silly, just let me pretend...
  TestApp.jsonStrung = JSON.stringify(TestApp.jsonContacts);
  
  TestApp.globalContactList = [];
  
  // my constructor function to create instances of Contact
  TestApp.Contact = function(name, age){
      this.name = name;
      this.age = age;
      TestApp.globalContactList.push(this);
  };
  
  // where I'm taking data and creating new Contact objects
  TestApp.instantiateObjects = function(){
      // I know this is silly, just let me pretend...
      var jsonUnstrung = JSON.parse(TestApp.jsonStrung);
      // I think I'm looping through the first set of objects sitting in jsonContacts
      for (var i in jsonUnstrung) {
          var obj = new TestApp.Contact(i.name, i.age);
          console.log(obj);
      }
      console.log(TestApp.globalContactList);
  };
  
  TestApp.instantiateObjects();
  </code></pre>