const sumDigits = num => num.toString().split('').map(Number).reduce((a,b) => a + b); //usage: mySum=sumDigits(myNum); console.log(sumDigits(1234)) output: 10