When using for-loop in Typescript, for some reason the for loop updates the whole array. Here is the code:
UpdatesToAllSelectedTabs() {
if (this.selectedOuterTabs[1]) {
this.outerTabs[1].InnerTabs = this.outerTabs[this.referencedOuterTab].InnerTabs;
for (let j = 0; j < this.outerTabs[1].InnerTabs.length; j++) {
this.outerTabs[1].InnerTabs[j].OuterTabId = this.outerTabs[1].Id;
}
}
}
The first version of the code had also the outer loop, but it also doesn't work proper with the fixed outer index ( in example above = 1). What this piece of code does, is the following:
If selected, copies the innerTabs from the referenced outerTab[0] to outerTab[1]. Which is ok. Then, it sets the ...innerTabs[j].OuterTabId from both outerTabs[1] and outerTabs[0] to the this.outerTabs[1].Id.
Can someone please explain what is happening here? Why are the outerTab[0] also updated?