I am currently working on a function that involves looping and using .subscribe to receive an array object each time, with the intention of later pushing this data into another array. The loop itself is functional; however, there is an issue with the results not aligning with expectations. Instead of printing the same array 20 times, the .subscribe part is printing the first array and then null arrays for the subsequent iterations. This behavior contradicts my understanding based on experience with other programming languages, as it first prints "Test" 20 times before moving inside the subscribe block.
Function:
testingFunction()
{
let i: number = 0;
while(i < 20){
console.log("Test");
this.testService.getAll().subscribe((object: any[]) => {
console.log(object);
})
i++;
}
}