title: If object property have same id, push into new array
body: <p>I would like to push the names into an new object if they have the same Id. The solution is not there yet, but I'm getting closer</p>
  <pre><code>const names = [
  {id:1,name:&quot;jame&quot;},
  {id:2,name:&quot;jill&quot;},
  {id:3,name:&quot;hanna&quot;},
  {id:3,name:&quot;clark&quot;}
  ]
  
  const newNames = []
  // Something like this
  names.foreach((person,index) =&gt; {
   if(newNames[index].id === person.id){
   newNames.push({id:person.index, names:[...newNames.name,person.name]})
   }else{
   newNames.push({id:person.index, person.name})
   }
  })
  
  </code></pre>
  <p>The outcome would look something like this:</p>
  <pre><code>const newNames = [
  {id:1,name:&quot;jame&quot;},
  {id:2,name:&quot;jill&quot;},
  {id:3,names: {name:&quot;clark&quot;,name:&quot;hanna&quot;}}
  ]
  </code></pre>
  <p>Issue: Cannot read properties of undefined (reading 'id')</p>