title: Reduce array of objects to a single object and call a function for each individual object
body: <p>I've an array of objects.
  I need to transform that to object of objects. While trying to do that, I need to call another function for each of the object.</p>
  
  <p>Could you please help me with this?</p>
  
  <p>Code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function convertData() {
   var arr = {"items": [ {"type": "color"}, {"type": "number" }]};
   arr.items.reduce(function(item, index) {
     return {
      /*for each obj in items call formatItems before assigning it here */
      item: formatItems(item)
     }
   });
  
    console.log(arr);
  }
  
  function formatItems(item, index) {
    return {
      type: "string",
      id: "item-"+index
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button onclick="convertData()"&gt;Click me!&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Expected Output:</p>
  
  <pre><code>{
    "0": {
      "type": "string",
      "id": "item-1"
    },
    "1": {
      "type": "string",
      "id": "item-2"
    }
  }
  </code></pre>