title: JavaScript: Converting Array to Object
body: <p>I am trying to convert an array to an object, and I'm almost there.</p>
  
  <p>Here is my input array:</p>
  
  <pre><code>[ {id:1,name:"Paul"},
    {id:2,name:"Joe"},
    {id:3,name:"Adam"} ]
  </code></pre>
  
  <p>Here is my current output object:</p>
  
  <pre><code>{ '0': {id:1,name:"Paul"},
    '1': {id:2,name:"Joe"},
    '2': {id:3,name:"Adam"} }
  </code></pre>
  
  <p>Here is my desired output object:</p>
  
  <pre><code>[ {id:1,name:"Paul"},
    {id:2,name:"Joe"},
    {id:3,name:"Adam"} ] 
  </code></pre>
  
  <p>Here is my current code:</p>
  
  <pre><code>function toObject(arr) {
    var rv = {};
    for (var i = 0; i &lt; arr.length; ++i)
      if (arr[i] !== undefined) rv[i] = arr[i];
    return rv;
  }
  </code></pre>