JSFiddle - React, Tailwind, and code Playground
JavaScript
var data = [
{yr : "2012", type : "B", qty : 1000},
{yr : "2012", type : "C", qty : 1000},
{yr : "2011", type : "B", qty : 1000},
{yr : "2012", type : "A", qty : 1000},
{yr : "2015", type : "A", qty : 1000}]
var yrs = [], types = [],tmp={};
data.forEach(function(item){
if(yrs.indexOf(item.yr)==-1){
yrs.push(item.yr)
}
if(types.indexOf(item.type)==-1){
types.push(item.type)
}
tmp[item.yr + item.type] = item;
});
yrs.forEach(function(yr){
types.forEach(function(type){
if(!tmp.hasOwnProperty(yr+type)){
data.push({yr: yr, type: type, qty: 0})
}
})
});
data.sort(function(a,b){
return b.yr === a.yr ? a.type > b.type : +a.yr - +b.yr
});
$('pre').text(JSON.stringify(data,null,' '))