Files
30-seconds-of-code/snippets/number-to-array-of-digits.md
Arjun Mahishi 6fe3ea4cc6 updated changes
2017-12-15 00:44:39 +05:30

14 lines
294 B
Markdown

### Number to array of digits
Convert the number to a string, split the string using `split()`.
use `parseInt()` to convert every element back to integer.
```js
const num2array = (n) =>{
return (''+n).split('').map((i) =>{
return parseInt(i);
})
}
// num2array(2334) -> [2, 3, 3, 4]
```