JSFiddle - React, Tailwind, and code Playground
JavaScript
var data = [
{"id":"564564867361367","date":"2017-12-21 12:07:07","image":"http:example1.jpg"},
{"id":"564564867361368","date":"2017-12-21 12:07:07","image":"http:example2.jpg"},
{"id":"564564867361368","date":"2017-12-21 12:07:07","image":"http:example3.jpg"},
{"id":"564564867361369","date":"2017-12-22 11:07:07","image":"http:example4.jpg"},
{"id":"564564867361370","date":"2017-12-22 15:07:07","image":"http:example5.jpg"},
{"id":"564564867361371","date":"2017-12-23 07:07:07","image":"http:example6.jpg"},
];
function getFormatedDate(dateStr){
var month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var date = new Date(dateStr);
return date.getDate() + ' ' + month[date.getMonth()];
}
var result = {};
data.forEach(function(item){
var d = getFormatedDate(item.date);
var b=item.id;
if(result[d]&&result[b]){
result[d].push(item);
result[b].push(item);
} else {
result[d] = [item];
result[b] = [item];
}
});
Object.defineProperty(result, 'print', {
enumerable: false,
get: function(){
var str = '';
for(var key in this){
str += key + '\n';
str += 'total: ' + this[key].length + '\n';
this[key].forEach(function(item){
str += 'id: ' + item.id + '\n';
str += 'image: ' + item.image + '\n';
str += 'date: ' + item.date + '\n';
});
}
return str;
}
});
alert(result.print);