I need to count numbers in a string. The numbers are separated by spaces. (1 2 3 4 10) I was trying to do this by charAt by that doesnt work if the number is not a single digit. I am relative new to JS and need some examples. I started with this but ran into a double digit #:
string1 = (1 1 1 4 10)
var total = parseFloat(0);
for(var j=0; j<string1.length; j++) {
total += parseFloat(string1.charAt(j));
}
Any help would be appreciated
string1 = (1 1 1 4 10)<--- that is not valid. Open up the developer console, you will see an error that points it out."Uncaught SyntaxError: Unexpected number"string1.match(/\d+/g).length.string1.match(/\d+/g).map(Number).reduce((a, b) => (a + b)).