I have to sort array of object based on array response of first API call. The data should be sorted in ascending order.
Currently I have first api call which returns list of array that will be used in the next api call.
this.service.fetchStories()
.pipe(
take(1),
).subscribe((res: any) => {
this.storyIds = res;
});
The first call return something like this.
[0001,0002,0003,0004,0005]
And I am looping over the storyIds and passed it in the card component
<div *ngFor="let id of storyIds | slice: start:end">
<app-cards [id]="id"></app-cards>
</div>
And I'm fetching the second api based on the ids in my card component
this.service.fetchStoryItems(this.id)
.pipe(
take(1)
)
.subscribe((res: StoryItem) => {
if (res !== undefined) {
this.data = res;
}
})
The second api returns each response after the loop
{name: 'John', score: 1}
{name: 'Jane', score: 99}
{name: 'Joe', score: 53}
I'm stuck here and want to sort items based on the score which is returned by the second api call.
I'm thinking something like pushing each object to an array and sort the new array of objects