Skip to content
Advertisement

How to sort or create a new array by grouping year and data

I need to sort this array of objects, in the format that gives me reading for the development of the layout below:

enter image description here

I arrived at this code, but it’s still not enough for what I need, besides that I’m not using the best practices… here’s the code:

JavaScript

Above also contains the array that I need to modify, I need it to look like the example below:

JavaScript

Advertisement

Answer

You can group the data using Array.prototype.reduce. Refer to snippet below:

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