Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js sum digits

// Sum of all the digits of a number in Javascript
const num = 1245,
    sum = num
        .toString()
        .split('')
        .map(Number)
        .reduce((a,b) => a + b);
console.log(sum); // 12
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #js #sum #digits
ADD COMMENT
Topic
Name
7+1 =