I need to sum all the prices inside an array so i can now the full price of all orders (the full price of all the items inside this array) in my application. But when i try to do it using the method .map i get "0" as the value. Im adding to my array all the values from the inputs that have the class ".total", not sure if this can be the issue
Can anybody help me?
var inputs = $(".total");
var arrTotal = [];
for (var i = 0; i < inputs.length; i++) {
arrTotal.push($(inputs[i]).val().replace("R$", ""));
}
let sum = 0;
arrTotal.map(e => sum += e)
console.log(sum);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<input class='total' value="1">
<input class='total' value="2">
<input class='total' value="3">