Answer the question
In order to leave comments, you need to log in
How to get an array of digits from a number?
const array = 45
console.log(array.method(45))
// [4, 5]
Answer the question
In order to leave comments, you need to log in
[...`${num}`].map(Number)
or
or
or
or
or
or
or
num.toString().split('').map(n => +n)
Array.from(String(num), parseFloat)
('' + num).match(/./g).map(n => parseInt(n))
Object.values(num.toFixed()).map(n => n | 0)
[].map.call(/.+/.exec(num)[0], n => n * 1)
eval('['.concat(num, ']').replace(/\d/g, '$&,'))
Object.assign([], JSON.stringify(num)).map(JSON.parse)
Array(1 + (Math.log10(num) | 0)).fill().map((n, i) => (num / 10 ** i | 0) % 10).reverse()
((f = (x, a) => (a.unshift(x % 10), x = x / 10 | 0, x ? f(x, a) : a)) => f(num, []))()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question