How do you group an array of objects by an object key to create a new array of objects based on the grouping? For example, I have an array of car objects:
const array = [
{red: [ {height: 50} ]},
{green: [ {height: 20} ]},
{blue: [ {height: 30} ]},
{blue: [ {height: 40} ]},
{red: [ {height: 10} ]},
{green: [ {height: 60} ]}
]
I want to create a new array of objects.(key is color)
const result = [
{red: [{height: 50}, {height: 10}]},
{green: [{height: 20}, {height: 60}]},
{blue: [{height: 30}, {height: 40}]}
]
I tried to use lodash.groupBy, however I don't know how to solve this problem at all.