

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to split JavaScript Number into individual digits?
To spilt a number into digits and print their sum, try to run the following code −
Example
<!DOCTYPE html> <html> <body> <script> var a = 28573; var sum = 0; while(a > 0) { sum += a % 10; a = Math.floor(a / 10); } document.write("Sum of digits = "+sum); </script> </body> </html>
Output
Sum of digits = 25
- Related Questions & Answers
- Number Split into individual digits in JavaScript
- How to split a number into digits in R?
- How can I split an array of Numbers to individual digits in JavaScript?
- Split number into n length array - JavaScript
- Split number into 4 random numbers in JavaScript
- Sum of individual even and odd digits in a string number using JavaScript
- Split string into groups - JavaScript
- Split a string and insert it as individual values into a MySQL table?
- Split string into equal parts JavaScript
- How to count digits of given number? JavaScript
- Java Program to split into a number of sub-strings
- Split keys and values into separate objects - JavaScript
- Can split array into consecutive subsequences in JavaScript
- How to split last n digits of each value in the array with JavaScript?
- How to split Python tuples into sub-tuples?
Advertisements