Skip to content
Advertisement

JavaScript Number Split into individual digits

I am trying to solve a math problem where I take a number e.g. 45, or 111 and then split the number into separate digits e.g. 4 5 or 1 1 1. I will then save each number to a var to run a method on. Does anyone know how to split a number into individual digitals?

For example I have a loop that runs on an array :

JavaScript

For each number, I would like to split its digits and add them together?

Advertisement

Answer

JavaScript

UPDATE: Calculating a sum

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement