How to merge objects with same key in javascript?
<p>I have a array called as <code>commondata</code></p>

<pre><code>commondata = [{
   giverUser: 'Abc',
   createdAt: '2016 11: 48: 40',
   note: 'Test'
 }, {
   giverUser: 'Xyz',
   createdAt: '12: 22: 37',
   note: 'Test data'
 }, {
   giverUser: 'Abc',
   createdAt: '2016 14: 22: 07',
   note: '"test123"'
 }];
</code></pre>

<p>When I am trying to merge the above array of object with following code, I am getting same array as it was.</p>

<p><strong>Below is my code:</strong></p>

<pre><code>commondata.forEach(function(a, i) {

  if (!this[a.giverUser]) {

    this[a.giveruser] = {
      giverUser: a.giverUser,
      createdAt: [],
      note: []
    };
    r_grouped.push(this[a.giveruser]);
  }

  this[a.giveruser].createdAt = this[a.giveruser].createdAt.concat(a.createdAt);
  this[a.giveruser].note = this[a.giveruser].note.concat(a.note);
}, Object.create(null));
</code></pre>

<p>What is wrong in above code ?
why I am not getting merger array with same giveruser ?</p>