JSFiddle - React, Tailwind, and code Playground
by HemalathaThanigaivel
HTML
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.0/moment.js"></script>
JavaScript
var dates = [
"2019-10-11 09:07:21",
"2019-10-10 10:03:51",
"2019-10-07 02:07:02",
"2019-11-27 08:02:45",
"2019-11-19 01:02:32",
"2019-12-01 22:13:21",
"2019-02-12 09:07:21",
"2019-05-18 04:02:29",
"2019-05-21 14:01:42",
"2019-07-11 01:16:29"
];
var groups = dates.reduce( function (acc, date) {
var yearWeek = moment(date).year()+'-'+moment(date).week();
// check if the week number exists
if (typeof acc[yearWeek] === 'undefined') {
acc[yearWeek] = [];
}
acc[yearWeek].push(date);
return acc;
}, {});
console.log(groups)