Question: I have a JSON object which looks like this: 

```
var allDataJson = [{"Researchers":"Laura, Mikael","Year":"2015"}, 
{"Researchers":"Mikko","Year":"2013",}, 
{"Researchers":"Harri","Year":"2015"}, .......] //long list 

```

I need to create a JSON object as follows:

```
 var myjson = [{"Year": 2015, "Total":60}, 
                  {"Year": 2014, "Total":68},
                  {"Year": 2013, "Total":72}]

```

For instance there are 60 `allDataJson` items with Year 2015. 

So far I only could get the year values. Any ideas about how to calculate `Total`? 

Here is my code:

```
function countPublicationsPerYear(allDataJson){
    var lookup = {};
    var items = allDataJson;
    var result = [];

    for (var item, i = 0; item = items[i++];) {
        var year = item.Year;
        count ++;
        if (!(year in lookup)) {
            var count = Object.keys(item).length;
            lookup[year] = 1;
            result.push({ "Year":year
            });
        }
    }
    return result; //returns Year: 2013, 2014, 2015
}

```

Answer: 
So you are trying to add total number of researchers ? 

**Answer**

```
function countPublicationsPerYear(allDataJson){
    var lookup = {};
    var items = allDataJson;
    var result = [];

    for (var item, i = 0; item = items[i++];) {
        var year = item.Year;
        count ++;
        if (!(year in lookup)) {
            lookup[year] = 1;
        } else {
            lookup[year]++;
        }
    }

    for (var property in lookup) {
        if (lookup.hasOwnProperty(property)) {
            result.push({"Year": property, "Total": lookup[property]});
        }
    }

    return result; //returns Year: 2013, 2014, 2015
}

```

```js
var allDataJson = [{"Researchers":"Laura, Mikael","Year":"2015"}, 
{"Researchers":"Mikko","Year":"2013",}, 
{"Researchers":"Harri","Year":"2015"}];

function countPublicationsPerYear(allDataJson){
        var lookup = {};
        var items = allDataJson;
        var result = [];

        for (var item, i = 0; item = items[i++];) {
            var year = item.Year;
            if (!(year in lookup)) {
                lookup[year] = 1;
            } else {
                lookup[year]++;
            }
        }

        for (var property in lookup) {
            if (lookup.hasOwnProperty(property)) {
                result.push({"Year": property, "Total": lookup[property]});
            }
        }

        alert(JSON.stringify(result));

        return result; //returns Year: 2013, 2014, 2015
    }

countPublicationsPerYear(allDataJson);
```
I ended up writing this snippet for you:

```
var totals = {};
for (var i=0; i<allDataJson.length; i++) {
    var researchYear = allDataJson[i].Year;
  if (researchYear in totals){ 
    totals[researchYear]++;
  } else {
    totals[researchYear] = 1;
  }
 };
console.log(totals); // your years summaries
console.log(JSON.stringify(totals)); //as json

```