How to combine the elements of the array with objects according to the total value?

Make the application to React that displays the weather using OpenWeatherMap API. The API returns the forecast about that.
[
 {dt: "2020-01-22 12:00", weather: "..."},
 {dt: "2020-01-22 16:00", weather: "..."},
 {dt: "2020-01-23 12:00", weather: "..."},
 {dt: "2020-01-23 16:00", weather: "..."},
 {dt: "2020-01-24 12:00", weather: "..."},
 {dt: "2020-01-24 16:00", weather: "..."},
...
]

The API returns time in Unix, for convenience, have written here in your view. Time then parsed using DatŠµ and is used in the component
You need to combine the elements of the array with the same day to your array, then to distribute the forecast for days.
Want to get the output like this array:
[
[
 {dt: "2020-01-22 12:00", weather: "..."},
 {dt: "2020-01-22 16:00", weather: "..."},
],
[
 {dt: "2020-01-23 12:00", weather: "..."},
 {dt: "2020-01-23 16:00", weather: "..."},
],
[
 {dt: "2020-01-24 12:00", weather: "..."},
 {dt: "2020-01-24 16:00", weather: "..."},
],
...
]


Need a complete example or at least a hint.
April 4th 20 at 13:21
1 answer
April 4th 20 at 13:23
Solution
Object.values(arr.reduce((acc, n) => {
 const [ date ] = n.dt.split(' ');
 (acc[date] = acc[date] || []).push(n);
 return acc;
}, {}))

Find more questions by tags JavaScript