0
I have an array that data comes from the user’s filled form and make a map:
dados.map(element=> {
var x
var number1 = parseInt(element.preco),
number2 = parseInt(element.peso)
var tota = number1 * number2
console.log(x += tota);
this.prod.push({
produto: element.produto,
peso: element.peso,
preco: element.preco,
total: element.preco * element.peso
})
})
And I wanted to know how to add up the total of all total
of Array
which is the preco * peso
, I tried to do it that way x+=tota
but he’s only adding the first two
Try to declare
var x
outside thedados.map()
, and see if it works.– Pedro Gaspar
As the friend answered above, declares a variable outside of . map, example
let allTotal
, and within the map after thevar tota = number1 * number2
you make athis.allTotal = this.allTotal + tota
– rafaelmacedo
I got it! obgg @rafaelmacedo
– Maria
The price is in whole? There is the
parseFloat()
also– Gaspar