I need a hand on this.
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 problem is the next:
When I do the slice and the push (this.positionsWholeAccUpdated.push(this.updatedPos)
and this.positionsWholeAccUpdated.splice(index, 1)
), is actually happening in this.allPositionsFromAllAccs
too for some reason (in both arrays). Why is that happening? I created a new array so I don't touch this.allPositionsFromAllAccs
at all, since I need it untouched. Any help on this?
Edit: solved with this: this.positionsWholeAccUpdated = JSON.parse(JSON.stringify(this.allPositionsFromAllAccs));