I am trying to gather all text values of my class .amount
into one array.
I know I can get the value of the first element with the class .amount using:
const myArray = document.getElementsByClassName('amount')[0].innerHTML;
But I want to get all values of all elements using .amount
My final goal is to build the sum of all values using this code:
function getArraySum(a){
const total=0;
for(const i in a) {
total += a[i];
}
return total;
}
console.log(getArraySum(myArray));
I am very new to JS and also open for other approaches.