title: How to group an array of objects based on multiple keys in Javascript?
body: <p>I have array as follows</p>
  
  <pre><code> [
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 1,
      "PostalCodeType": "ShipToCustomer",
      "TimeStart": "1970-01-01T06:00:00.000Z",
      "TimeEnd": "1970-01-01T15:59:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 1,
      "PostalCodeType": "ShipToCustomer",
      "TimeStart": "1970-01-01T16:00:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 1,
      "PostalCodeType": "ShipToCustomer",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T05:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 2,
      "PostalCodeType": "ShipToCustomer",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T15:59:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 2,
      "PostalCodeType": "ShipToCustomer",
      "TimeStart": "1970-01-01T16:00:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 3,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T15:59:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 3,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T16:00:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 4,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T15:59:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 4,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T16:00:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 5,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T16:22:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 5,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T16:23:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 6,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T15:59:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 6,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T16:00:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 1,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T06:00:00.000Z",
      "TimeEnd": "1970-01-01T15:59:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 1,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T16:00:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 1,
      "ShippingCarrierId": 1,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T05:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 2,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T00:00:00.000Z",
      "TimeEnd": "1970-01-01T15:59:00.000Z",
      "PickupTimeSlot": "PM",
      "DaysToAdd": 0,
      "PickupTime": "1970-01-01T17:00:00.000Z"
    },
    {
      "WarehouseId": 2,
      "ShippingCarrierId": 2,
      "PostalCodeType": "ShipToDS",
      "TimeStart": "1970-01-01T16:00:00.000Z",
      "TimeEnd": "1970-01-01T23:59:00.000Z",
      "PickupTimeSlot": "AM",
      "DaysToAdd": 1,
      "PickupTime": "1970-01-01T11:00:00.000Z"
    }
  ]
  </code></pre>
  
  <p>I want to group it by <code>WarehouseId</code>, <code>ShippingCarrierId</code> and PostalCodeType.
  Each objec will have chlid array of objects for Timestart, TimeEnd etc</p>
  
  <p>How can I achieve this</p>
  
  <p>output like :</p>
  
  <pre><code>PickupTimeTable: [{
              WarehouseId: 1,
              ShippingCarrierId: 1,
              PostalCodeType: 'ShipToCustomer',
              PickupTimeSlots: [{
                      StartTime: '06:00:00.0000000',
                      EndTime: '15:59:00.0000000',
                      Slot: 'PM',
                      PickupTime: '17:00:00.0000000',
                      DaysToAdd: 0
                  },
                  {
                      StartTime: '16:00:00.0000000',
                      EndTime: '23:59:00.0000000',
                      Slot: 'AM',
                      PickupTime: '11:00:00.0000000',
                      DaysToAdd: 1
                  },
                  {
                      StartTime: '00:00:00.0000000',
                      EndTime: '05:59:00.0000000',
                      Slot: 'AM',
                      PickupTime: '11:00:00.0000000',
                      DaysToAdd: 0
                  },
              ]
          }, ]
  </code></pre>