Question: I want to make an array of objects grouped by the date property.

```
let data = [
        { Age: "(60-100)", Date: "28/05/20" },
        { Age: "(60-100)", Date: "28/05/20" },
        { Age: "(4-6)", Date: "28/05/20" },
        { Age: "(60-100)", Date: "29/05/20" },
        { Age: "(38-43)", Date: "29/05/20" },
        { Age: "(4-6)", Date: "29/05/20" },
        { Age: "(38-43)", Date: "30/05/20" },
        { Age: "(38-43)", Date: "30/05/20" }
    ];

```

I want the output like

```
 result = [
        { Date: "28/05/20", "(60-100)": 2, "(4-6)": 1 },
        { Date: "29/05/20", "(38-43)": 1, "(4-6)": 1, "(60-100)": 1 },
        { Date: "30/05/20", "(38-43)": 2 },
    ]

```

Answer: 
Give this a try.

```
 let data = [
      { Age: "(60-100)", Date: "28/05/20" },
      { Age: "(60-100)", Date: "28/05/20" },
      { Age: "(4-6)", Date: "28/05/20" },
      { Age: "(60-100)", Date: "29/05/20" },
      { Age: "(38-43)", Date: "29/05/20" },
      { Age: "(4-6)", Date: "29/05/20" },
      { Age: "(38-43)", Date: "30/05/20" },
      { Age: "(38-43)", Date: "30/05/20" }
 ];

 let res = [];
 data.map((d, index) => {
      if (!res.some(val => val.Date === d.Date)) {
           d[`${d.Age}`] = 1
           res.push(d)
           delete(d.Age)
      } else {
           let index = res.findIndex(val => val.Date == d.Date);
           let _d = res[index];
           if (_d.hasOwnProperty(`${d.Age}`)) {
                _d[`${d.Age}`] = parseInt(_d[`${d.Age}`] + 1)
           } else {
                _d[`${d.Age}`] = 1
           }
           res[index] = _d;
      }
 })

 console.log(res)

```
try this:

```
var result={};
for(var item of data) {
  if(result[item.Date]==undefined) result[item.Date]={};
  if(result[item.Date][item.Age]==undefined) result[item.Date][item.Age]=0;
  result[item.Date][item.Age]++;
}

```

This gives you an object (not an array) with keys of Date and values as object with keys of Age and values as count.  

If you still need an array, you can iterate over the result and construct an array.

```
result=={
  "28/05/20": {
    "(60-100)": 2,
    "(4-6)": 1
  },
  "29/05/20": {
    "(60-100)": 1,
    "(38-43)": 1,
    "(4-6)": 1
  },
  "30/05/20": {
    "(38-43)": 2
  }
}

```

If you want the array, you can create `resultArr=[]`, iterate over keys of result, tempObj, add key "Date" and value of iterated key, then iterate over keys of iterated key, add each "Age" with it's count, then push tempObj into resultArr...