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

294 B

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.

const num2array = (n) =>{
	return (''+n).split('').map((i) =>{
		return parseInt(i);
	})
}

// num2array(2334) -> [2, 3, 3, 4]