title: How can I prevent duplicate keys when adding data to an object array?
body: <p>I have some code where I am looping through some records in a table, and whilst doing this I'm organising this data into a JavaScript object array.</p>
  
  <p>For example the data below.</p>
  
  <p><a href="https://i.stack.imgur.com/OzImm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OzImm.png" alt="enter image description here"></a></p>
  
  <p>I need to ensure that if a record "Name" has already been recorded, then rather than create a new item it uses the existing item so that the end result will be an object or array like this:</p>
  
  <pre><code>{
      "bobjones": {
           "sessions": 7
      },
      "annfrank": {
           "sessions": 4
      },
      "fredsmith": {
           "sessions": 4
      }
  }
  </code></pre>
  
  <p>Doing this in PHP is easy, but I'm struggling with this in JS due to the way keys are interpreted. Could somebody provide some direction?</p>