Files
30-seconds-of-code/snippets/number-to-array-of-digits.md
Arjun Mahishi 9ef13d7140 updated changes
2017-12-15 00:37:32 +05:30

14 lines
307 B
Markdown

### Number to array of digits
use `parseInt()` to get only the integer part of the quotient.
use `Array.reverse()` to return the array in the same order as the number.
```js
const num2array = (n) =>{
return (''+n).split('').map((i) =>{
return parseInt(i);
})
}
// num2array(2334) -> [2, 3, 3, 4]
```