You can do this using regex to match all digits (.match(/\d+/g)) and then use .reduce to sum the digits matched:
const str = 'hel4l4o';
const total = str.match(/\d+/g).reduce((sum, n) => sum + +n, 0);
console.log(total);
As for your code, you need to loop through your characters and then check if it is a number using if(!isNaN(char)). After that you need to turn the character into a number by using something like the unary plus operator (+char) such that you can add it to total:
let str = 'hel4l4o';
function sumDigitsg(str) {
let total = 0;
for(let i = 0; i < str.length; i++) {
let char = str[i];
if (!isNaN(char)) {
total += +char;
}
}
return total;
}
console.log(sumDigitsg(str));