Iterating Integers With No Commas


I’ve tried many ways to iterate and sum an integer with no commas. Below was my most recent effort to at least access it and loop through, but I still can’t figure it out. Please help.

let nums = 4444444;
let splitNums = Number(nums.toString().split(" "))

let splitNums = nums.toString().split("") this will create an array of the numbers, currently you have a space in your split method so what you are actually doing is creating an array that looks like this ["4444444"] and then you are running calling the number constructor on it, and that normally return NaN on an array, but you only have one element so it its just calling it on that instead so the short and sweet of it is all you are doing is making splitNums have the same value as nums.

1 Like

If you use my method it will look like this ["4", "4", "4", "4", "4", "4", "4"]

1 Like

That was the problem I kept having. I just ended up creating an array using the method below.