title: Convert array to object using values like keys
body: <p>I have a project in Typescript in which I am trying to create a function that converts an array into an object using the first values as keys of the object.</p>
  <p>This is my array:</p>
  <pre><code>let testArr = [&quot;id&quot;, &quot;ser&quot;, &quot;add&quot;, &quot;1&quot;, &quot;asd&quot;, &quot;82.255&quot;, &quot;2&quot;, &quot;ert&quot;, &quot;82.119&quot;, &quot;3&quot;, &quot;pol&quot;, &quot;82.250&quot;];
  </code></pre>
  <p>This is what I need:</p>
  <pre><code>let newArr = [
    {
      &quot;id&quot;: &quot;1&quot;,
      &quot;ser&quot;: &quot;asd&quot;,
      &quot;add&quot;: &quot;82.255&quot;
    },
    {
      &quot;id&quot;: &quot;2&quot;,
      &quot;ser&quot;: &quot;ert&quot;,
      &quot;add&quot;: &quot;82.119&quot;
    },
    {
      &quot;id&quot;: &quot;3&quot;,
      &quot;ser&quot;: &quot;pol&quot;,
      &quot;add&quot;: &quot;82.250&quot;
    }
  ]
  </code></pre>
  <p>In result I store the data of the array that I want to use as keys of the object:</p>
  <pre><code>let chunk = 3;
  
  let result = testArr.reduce((resultArray, item, index) =&gt; { 
      const chunkIndex = Math.floor(index/chunk)
  
      if(!resultArray[chunkIndex]) {
          resultArray[chunkIndex] = [] // start a new chunk
      }
  
      resultArray[chunkIndex].push(item)
  
      return resultArray
  }, [])
  </code></pre>
  <p>My problem is that I don't know how to use that data as keys of the object and I would like to know how to convert the result variable into a generic function for any array and any number.</p>