Javascript return array of objects
<pre><code>function setup() {
  var names = [];
  var name = {firstname: "", lastname: ""};

  name.firstname = "John";
  name.lastname = "Doe";
  names.push(name);

  name.firstname = "Bill";
  name.lastname = "Smith";
  names.push(name);

  return names;
}

var temp = setup();
print temp[0].firstname;
</code></pre>

<p>I can't seem to figure out how to return an array of objects from a function. Any idea where I'm going wrong?</p>

<p>The problem is that the result stored in <code>temp</code> is the following:</p>

<pre><code> [
   {
     firstname: "Bill",
     lastname: "Smith"
   },
   {
     firstname: "Bill",
     lastname: "Smith"
   }
 ]
</code></pre>