Skip to content
Advertisement

Grouping array of objects by multiple keys

I feel embarrassed for asking this question as I should know how to figure it out, but I’m spinning my wheels on grouping an array of objects by multiple keys.

Here’s the data:

JavaScript

What I’ve been trying to generate with little success is the following:

JavaScript

The schema is:

JavaScript

I’ve tried the following with lodash

JavaScript

This gets me part of the way, but I end up with incomplete data when it comes to the styles and types for each year of the car.

Advertisement

Answer

You could use a hash object and a nested approach for the given properties.

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