Summation problems using vector

0

Well, I'm facing problems with a vector. The idea would be to go through the vector and add its values in a var. The problem: Enter 1000, it traverses and assigns 1000 to var. But when I re-type the value 500, it returns 2500. Here is the code:

    if (this.vetCarrinhoAux.indexOf(element) === -1) {
      this.vetCarrinhoAux.push(this.totCar);

    }

   for(let i=0; i <= this.vetCarrinhoAux.length; i++){
       this.acumulador += this.vetCarrinhoAux[i];
    }
    
asked by anonymous 30.10.2018 / 14:11

0 answers