Can anyone offer some assistance with this issue?
getPositionsPortfolioUpdated(){
this.positionsWholeAccUpdated = [];
this.positionsWholeAccUpdated = this.allPositionsFromAllAccs
this.positionsWholeAccUpdated.forEach((pos, index) => {
if (pos.ticker === this.ticker) {
this.updatedPos = pos;
this.updatedPos.direction = this.calculationData.position.updated.direction;
this.updatedPos.size = this.calculationData.position.updated.quantity;
this.updatedPos.value = this.calculationData.position.updated.value;
this.positionsWholeAccUpdated.splice(index, 1)
this.positionsWholeAccUpdated.push(this.updatedPos)
}
})
}
The main issue I'm facing is: When I perform the slice and push operations (
this.positionsWholeAccUpdated.push(this.updatedPos)
and this.positionsWholeAccUpdated.splice(index, 1)
), it seems to be affecting this.allPositionsFromAllAccs
as well for some unknown reason (modifying both arrays). What could be causing this? I made sure to create a new array so that I wouldn't impact this.allPositionsFromAllAccs
in any way, as I need it to remain unchanged. Any insights on how to resolve this?
Edit: Issue resolved after using this workaround: this.positionsWholeAccUpdated = JSON.parse(JSON.stringify(this.allPositionsFromAllAccs));