[
{
date:"2015-01-22",
dog:1
},
{
date:"2015-01-22",
cat:2
},
{
date:"2015-01-22",
duck:3
}
]
[
{
date:"2015-01-22",
dog:1,
cat:2,
duck:3
}
]
var arr1 = [
{date:"2015-01-22", dog:1},
{date:"2015-01-22", cat:2},
{date:"2015-01-22", duck:3},
{date:"2015-01-22", duck:2},
{date:"2015-01-22", cat:3},
{date:"2015-01-22", dog:4}
],
arr2 = [];
for (var i = 0; i < arr1.length; i += 1) {
if (arr2[arr1[i].date] && arr2[arr1[i].date].date) {
for (n in arr1[i]) {
if (n !== 'date') {
arr2[arr1[i].date][n] = (arr2[arr1[i].date][n]) ? arr2[arr1[i].date][n] + arr1[i][n] : arr1[i][n];
}
}
} else {
arr2[arr1[i].date] = arr1[i];
}
}
console.log(arr2);