title: Convert array to objects using JavaScript/AngularJS
body: <p>I need convert arrays inside my parent array to objects to match my database model data.</p>
  
  <p>I have array like this:</p>
  
  <pre><code>emails: Array[2] 
  0: "example@mail.com"
  1: "otherexample@mail.com"
  id: 1 
  firstname: "Jane"
  lastname: "Doe
  </code></pre>
  
  <p>What I want to achieve is to convert emails array to array of objects like this:</p>
  
  <pre><code>    emails: Array[2] 
      0: 
  {
  name: "example@mail.com"
  }
      1: 
  {
  name: "otherexample@mail.com"
  }
      id: 1 
      firstname: "Jane"
      lastname: "Doe
  </code></pre>
  
  <p>I tried to use this code to convert array to object but for some reason it fails (no data are displayed -> variable rv is empty):</p>
  
  <pre><code> var rv = {};
          for (var i = 0; i &lt; dbInfo.emails.length; ++i)
              if (dbInfo.emails[i] !== undefined) rv[i] = dbInfo.emails[i];
  </code></pre>
  
  <p>Does someone knows why my code fails and does someone knows solution for this type of problem? </p>
  
  <p>Thanks advance.</p>