Convert JavaScript Number to Number Array
· Reading time: ~1 minute(s) (89 words) programming javascriptI 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:
|
|
This results in output
containing an array with the contents of [4, 3, 2, 3, 7, 5]
.