I'm using Angular 14.
I have an Observable that is an Array of Objects, looks like a dictionary with key/values.
Array: [
0: Object {id: 100, manufacturer: 'ford', model: 'mustang'},
1: Object {id: 110, manufacturer: 'ford', model: 'fiesta'},
2: Object {id: 150, manufacturer: 'ford', model: 'escort'},
3: Object {id: 320, manufacturer: 'Toyota', model: 'camry'},
4: Object {id: 325, manufacturer: 'Toyota', model: 'rav4'},
5: Object {id: 345, manufacturer: 'Toyota', model: 'corolla'},
]
I want to group this array by manufacturer. I need two separate lists for Ford and Toyota.
I have read about the RxJs .groupBy() but I can't get it to work as this is a dictionary.
this.cars$.pipe(
groupBy(g => g[??????].manufacturer),
mergeMap(group => group.pipe(toArray()))
).subscribe(s => { .... });
I have also read about the Javascript reduce() function but it is difficult to understand and I can't find an example of it reducing a dictionary.
Any help appreciated!