How to convert array of objects to given format using JavaScript
<p>I need to format an array of data using JavaScript. I am using the following data:</p>

<pre><code>var response = [{
      day_id:1,
      day_name:"Monday",
      subcat_id:"2",
      cat_id:"1",
      comment:"hii"
}, {
      day_id:1,
      day_name:"Monday",
      subcat_id:"1",
      cat_id:"2",
      comment:"hello"
}
 {
      day_id:2,
      day_name:"Tuesday",
      subcat_id:"3",
      cat_id:"2",
      comment:"hii"
}]
</code></pre>

<p>... and I need to convert it to the following format</p>

<pre><code>var responseNew = {
      data: [{
        day_name: "Monday",
        day_id:1
        answers:[{
          cat_id:1,
          subcat_id:1,
          comment:'hii'
        },{
          cat_id:1,
          subcat_id:2,
          comment:'hello'
        }]
      }, {
        day_name: "Tuesday",
        day_id:2
        answers:[{
          cat_id:3,
          subcat_id:2,
          comment:'hello'
        }]
      }, {
        day_name: "Wednesday"
         day_id:3
      }, {
        day_name: "Thursday"
         day_id:4
      }, {
        day_name: "Friday"
         day_id:5
      }, {
        day_name: "Saturday",
         day_id:6
      }, {
        day_name: "Sunday"
         day_id:7
      }]
    };
</code></pre>

<p>I want to convert my first array into the second format. One condition is if other day_id is not present it simply sets the day name and day id in static as given above.</p>