title: Pushing to an array inside an object
body: <p>I just recently picked up JS and have been working on an exercise to sort people from an array of records, <code>ancestry</code>, into the centuries they lived in and their ages. Here's a sample element from <code>ancestry</code>:</p>
  
  <pre><code>{
  name:   "Carolus Haverbeke"
  sex:    "m"
  born:   1832
  died:   1905
  father: "Carel Haverbeke"
  mother: "Maria van Brussel"
  }
  </code></pre>
  
  <p>Here's my attempt:</p>
  
  <pre><code>ancestry.forEach(function(person) {
    var ages = {};
    var century = Math.ceil(person.died / 100);
  
    if (century in ages) 
      ages[century].push(person.died - person.born);
    else
      ages[century] = person.died - person.born;
  });
  </code></pre>
  
  <p>This is the general format I'm trying to store in <code>ages</code>, which maps each century to an array of the people's ages:</p>
  
  <pre><code>{
  16: [24, 51, 16]
  17: [73, 22]
  18: [54, 65, 28]
  }
  </code></pre>
  
  <p>I'm really confused as this code only saves the first person in <code>ancestry</code> into <code>ages</code>. I thought it might be because I defined <code>ages</code> inside the <code>forEach</code>, but when I move <code>var ages = {}</code> outside I get this: </p>
  
  <p><code>TypeError: ages[century].push is not a function (line 18)</code></p>
  
  <p>Could someone please help explain what's going on and the code should be fixed?</p>