I'm currently working on sorting an array of dynamic key / value pairs (Objects) based on a specific property within the object. Can anyone provide me with an example of how to accomplish this? I will attempt to replicate a similar structure for my issue.
Here is an example of the Order Class:
export class Order {
id: number;
productRank: number;
productId: number;
productName: string;
}
In my component, there is an observable array called storeOrders containing orders:
storeOrders$: Observable<Array<Order>>;
The keys in the orders array are dynamically generated and stored as key/value pairs with the key being represented by the order object.
For example, the orders object looks something like this:
let orders = {
12_123: { id: 123, productRank: 3, productId: 23, productName: 'shirt'},
23_124: { id: 124, productRank: 1, productId: 14, productName: 'cologne'},
67_124: { id: 125, productRank: 2, productId: 45, productName: 'belt' }
}
When subscribing to this data, how can I iterate over the storeOrders array and sort the items based on the productRank property? I've been struggling to get this right and would appreciate any guidance on how to iterate over dynamic keys in an array and perform a sort based on a property within the value object. Thank you for your help!