I have a repeat structure that should add up some values:
The variable qtdeEstoque
has been defined as number
and the variable variacaoForm.value.variacoes.estoque_variacao
is a number, but when I try to add this way instead of incrementing the value it puts in front, for example: number 10
and 5
, it joins and stays 105
:
for(let i=0;i<this.variacaoForm.value.variacoes.length;i++){
this.qtdeEstoque+= this.variacaoForm.value.variacoes[i].estoque_variacao
}
console.log(this.qtdeEstoque);
I tried some other ways using toInt()
and Number()
:
for(let i=0;i<this.variacaoForm.value.variacoes.length;i++){
this.qtdeEstoque+= Number(this.variacaoForm.value.variacoes[i].estoque_variacao)
}
console.log(this.qtdeEstoque);
But it returns NAN
, how can I fix this?