Nested ngFor repeats first and last elements more than once

I’ve this code which is supposed to create a table and it creates but, the first and last elements are repeated:

ng-container(*ngFor="let provinces of generateArray(generalInformation)")
  ng-container(*ngFor="let districts of generateArray(provinces.value); let districtIndex = index")
    ng-container(*ngFor="let court of districts.value; let courtIndex = index")
      tr
          td(*ngIf="districtIndex==0", [attr.rowspan]="countRecursively(provinces.value)-generateArray(provinces.value).length") {{provinces.key}}
          td(*ngIf="courtIndex==0", [attr.rowspan]="generateArray(districts.value).length") {{districtIndex+1}}. {{districts.key}}
          td {{courtIndex+1}}. {{court}}

the output is:

what I want is:

Any help would be appreciated!

What language is this?