title: Issue adding key value pair to javascript object from an array
body: <p>I have an object like this</p>
  
  <pre><code>let obj = {
      "apple": {
      "color": "red",
    },
    "banana": {
      "color": "yellow"
    }
  }
  </code></pre>
  
  <p>I am getting an array of objects of this form </p>
  
  <pre><code>let arr = [
    {
      "count": "9904",
      "fruit": "apple",
      "type": "typea"
    },
      {
      "count": "7142",
      "fruit": "banana",
      "type": "typeb"
    },
    {
      "count": "4121",
      "fruit": "apple",
      "type": "typec"
    }
  ]
  </code></pre>
  
  <p>I want to combine these two so that each item in <code>obj</code>can have variable no of properties so that final output look something like this</p>
  
  <pre><code>{
      "apple": {
      "color": "red",
      "typea": "9904",
      "typec": "4121"
    },
    "banana": {
      "color": "yellow",
      "typeb": "7142"
    }
  }
  </code></pre>
  
  <p>I tried running the array through a for loop but when I try to use the dynamic values in keys it shows error</p>
  
  <pre><code>for (let item of arr){
      obj[item.fruit] = {...obj[item.fruit], item.type: item.count}
  }
  </code></pre>
  
  <p>If instead of <code>item.type</code> I put some static value like <code>"count"</code> it works but I can't figure out how to use dynamic value</p>
  
  <p>Can anyone suggest me what is the best way to accomplish this?</p>