Skip to content
Advertisement

How to group according to date{ the key in each object is the day – from the first day of the month untill the current date}

JavaScript

Given the array above, my goal is to return an array of object that are group according to date(On Rent). But first I need to get the start of the month (for example this month is september, and also the current date of this month so for example Sept 25) so my final output should be like this

JavaScript

Also I made this code but I need to get the firstDateOfTheMonth and the currentDate

JavaScript

Advertisement

Answer

Grouping approach

  1. Make an empty object days with key as date like
JavaScript
  1. Merge empty object with an array

  2. Get only values of merged object

Live Demo

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement