Sum of Digits

Calculate the sum of all digits in a number.

Code

General
String(Math.abs(num)).split('').reduce((sum, d) => sum + Number(d), 0);

Parameters

Number

Browser·fetch() may be limited by CORS

More JavaScript Snippets