I had a number which I wanted converting into an array where each digit of the number was an item in the array. I tried a few different ways of doing this but always ended up with a string array which wasn’t what I wanted.

To get around this, you can use some of the new features introduced in ES6 as follows:

1
2
const theNumber = 432375;
const output = Array.from(theNumber.toString()).map(Number);

This results in output containing an array with the contents of [4, 3, 2, 3, 7, 5].