JavaScript, Split Number To Digits


How to split a number to Digits using JavaScript?

The Logic: Convert the number to string, split it into a string array and convert each string to number

function splitNumber(num){
	return String(num).split('').map(item => Number(item))
}

console.log('Number array is ', splitNumber(123));
// "Number array is ", [1, 2, 3]