How to find sum of integers in a string using JavaScript
问题 I created a function with a regular expression and then iterated over the array by adding the previous total to the next index in the array. My code isn't working. Is my logic off? Ignore the syntax function sumofArr(arr) { // here i create a function that has one argument called arr var total = 0; // I initialize a variable and set it equal to 0 var str = "12sf0as9d" // this is the string where I want to add only integers var patrn = \\D; // this is the regular expression that removes the