0

I'm experiencing a rare problem when working with an array in Angular that I struggled with for several hours. I have this code here:

console.log(partner.myArray);

partner.myArray.forEach(e => {
   console.log(e);
   console.log('_____________________________');
});

The first console output shows an empty array, as you can see here: enter image description here

but when iterating over the same array and printing each element, it somehow shows some entries: enter image description here

I struggled with that for a long time and now I'm pushing each element into a new array before using it, because I haven't found another solution. I'd really like to know how this can be, because I never had such a problem in typescript. Does anybody have an explanation for that?

Maxim
  • 227
  • 2
  • 14
  • Maybe you experience an effect caused by how the console output is evaluated https://stackoverflow.com/questions/42260524/array-length-is-zero-but-the-array-has-elements-in-it – Martin May 17 '23 at 09:34
  • I want to see where you are defining the array and how you are loading it because it seems that your array is being loaded before initializing. – Asna Khan May 17 '23 at 13:26

0 Answers0