Let's say I have an array of objects like this:
[
{ "type": 121, "model": "model1" },
{ "type": 128, "model": "model2" },
{ "type": 130, "model": "model2" },
{ "type": 130, "model": "model2" }
]
And I want to filter through it and create new objects based on the model field.
With the end result being:
[
{ "type": 121, "model": "model1" }
]
[
{ "type": 128, "model": "model2" },
{ "type": 130, "model": "model2" },
{ "type": 130, "model": "model2" }
]
I'm using typescript and lodash so anything with that would be best
I tried lodash groupBy and ES6 mapping, but no success so far. I guess I could do it in a dirty way with multiple forEach loops but I'm pretty sure there is a much easier way.
codeorhttps://stackblitz.com/?