Currently, I am attempting to utilize underscore to create an array of entities that are grouped by their respective locations.
The current format of the array consists of pairs in this structure { location: Location, data: T}[]
. However, I aim to rearrange it so that it is grouped by location and appears like this
{ location: Location, data: T[]}>[]
Initially, my approach involved using _.GroupBy
const entitiesMap = entities.map(e => ({ location: this.options.locationResolver(e), data: e}));
this.locationEntitiesMap = _.groupBy(entitiesMap, entityPair => entityPair.location);
However, upon implementation, I noticed that this method returns an object with the location as the Key. How can I modify this to return a grouped array instead?