I'm trying to aggregate the array (arr) below so that I get an output such as:
Desired Output: [['2011-04-11','Open',6],['2011-04-11','Closed',4]]
but I'm getting: Output: [2011-04-11,Open: 6, 2011-04-11,Closed: 4]
How can I take the javascript array map and convert to desired out.
Source code excerpt:
var arr = [
['2011-04-11', 'Open'],
['2011-04-11', 'Closed'],
['2011-04-11', 'Closed'],
['2011-04-11', 'Open'],
['2011-04-11', 'Open'],
['2011-04-11', 'Open'],
['2011-04-11', 'Closed'],
['2011-04-11', 'Closed'],
['2011-04-11', 'Open'],
['2011-04-11', 'Open']
];
var hist = [];
arr.map(function(a) {
if (a in hist)
hist[a]++;
else
hist[a] = 1;
});
map, just return something. Also you want to useindexOfnotinwhen working with arrays. Otherwise use an object if your keys are not numeric.