let value = "12AB34";//given string let val1 = value.split("");//split string //filter out the character and keep numbers let val2 = val1.filter(c =>{ if (c >= '0' && c <= '9') { return c; } }); //sum all the numbers in array let sum = 0; val2.forEach(x => {sum += parseInt(x);}); console.log(sum);