I am facing a scenario where I have an array containing IDs and I need to subscribe to observables for each ID in a sequential order. I attempted to use a foreach loop but the responses were not in the desired order. Then, I tried to implement a for loop and increment the index from the subscriber, but this caused the browser to crash due to a large number of requests being sent before the index changed.
Here is the code snippet I was working with:
const uniqueGroups=[1,2,3,4,5,6];
uniqueGroups.forEach(groupId => {
this.magB1BaseService.getAttributeGroup(groupId)
.subscribe(data => {
this.AttributeGroups.push(data);
this.AttributeGroupsCollapses[data.ID] = false;
});
});