title: Using groupBy and map to transform data using LoDash and Moment
body: <p>I am inexperienced with lodash, but I believe it can help me transform data into a desired format. I have tried varying level of methods described in the documentation, but I can not wrap my head around everything. I've looked here on SO, a few blogs, and the documentation. I have tried combining groupby and map, but I was unable to resolve the issue. I was also unsure how to log the steps. </p>
  
  <p>Here is what I want to do, I want to take the following array and turn it into the array after it. Can anyone point me in the right direction?</p>
  
  <p><strong>Original Data</strong></p>
  
  <pre><code>var mockData = [
        {
          "notice_title": "Bad news",
          "notice_text": "Server is down!",
          "start_date": "2016-09-18T04:00:00Z"
        },
        {
          "notice_title": "Weekly Reminder",
          "notice_text": "Please read the assignment!",
          "start_date": "2016-09-18T04:00:00Z"
        },
        {
          "notice_title": "Sweet",
          "notice_text": "This morning, the new edition of our blog hit stands!",
          "start_date": "2016-09-19T04:00:00Z"
        },
        {
          "notice_title": "Yeah",
          "notice_text": "This is pretty cool",
          "start_date": "2016-09-19T04:00:00Z"
        }
  </code></pre>
  
  <p><strong>Desired Data</strong></p>
  
  <pre><code>var newMockData = [
      { 
          "date": "JAN 18 2016", 
          "messages": [{
              "notice_title": "Bad news",
              "notice_text": "Server is down!",
              "start_date": "2016-09-18T04:00:00Z"
            },
            {
              "notice_title": "Weekly Reminder",
              "notice_text": "Please read the assignment!",
              "start_date": "2016-09-18T04:00:00Z"
            }],
          "date": "JAN 19 2016", 
          "messages": [{
              "notice_title": "Sweet",
              "notice_text": "This morning, the new edition of our blog hit stands!",
              "start_date": "2016-09-19T04:00:00Z"
            },
            {
              "notice_title": "Yeah",
              "notice_text": "This is pretty cool",
              "start_date": "2016-09-19T04:00:00Z"
            }]
  
  }]
  </code></pre>
  
  <p><strong>Updated lodash</strong></p>
  
  <pre><code>var result = _.chain(mockData)
        .groupBy(function(item) {
          return moment(item.start_date.substring(0,10)).format("MMM-DD-YYYY"); 
        })
        .map((value, key) =&gt; {
          return {
            date: key, 
            param: value
          }
        })
        .value();
  </code></pre>