[Solved] What would be the best way to sort events according to its date


First you need to convert it to an array:

var events = Object.keys(obj).map((key) => {
  return Object.assign({}, obj[key], {eventName: key});
});

Then you need to group them by date. We can do this with lodash.

var groupBy = require('lodash/collection/groupBy');

var eventsWithDay = events.map((event) => {
  return Object.assign({}, event, {day: new Date(event.date).setHours(0, 0, 0, 0))
});

var byDay = groupBy(eventsWithDay, 'day');

And byDay will be an object with a key for each date with a value of an array of events for that day.

1

solved What would be the best way to sort events according to its date