I want to convert an integer, say 12345, to an array like [1,2,3,4,5].
12345
[1,2,3,4,5]
I have tried the below code, but is there a better way to do this?
I'd go with
var arr = n.toString(10).replace(/\D/g, '0').split('').map(Number);
You can omit the replace if you are sure that n has no decimals.
replace
n