I searched for a solution but could not find,
I have the current script, the numbers are random (changing at different amounts),
var totalAmount = [55.99,7.00];
I’m trying to add the two values separated by the comma to equal e.g.”totalAmout = 62.99;“
You changed it to an array. You can add to an array in javascript with
.push();[edit] Yeah, the whole format of the question threw me off. If you’re wanting the SUM of an array of numbers, you can do so with a for loop:
totalwill have the sum of the array, and it work for any length array. If we didn’t have parseFloat, it might do some weird things since the concatenate and addition operators are both+in JavaScript. So we doparseFloat(totalAmount[i])and that will make sure if even if you have a string like"55.55"in your array, it will be used as a number and not a string.