To separate an integer into separate digits in an array in JavaScript, we use the split
method.
For instance, we write
const n = 123456789;
const digits = n.toString().split("");
to call toString
to convert n
to a string.
Then we call split
to split the string into the individual digit strings.