how to turn a number to array javascript code example
Example 1: turn number into array javascript
const myNumber = 1245;
function numberToArray(number) {
let array = number.toString().split("");
return array.map(x => parseInt(x));
}
var myArray = numberToArray(myNumber);
Example 2: convert number to array javascript
const numToSeparate = 12345;
const arrayOfDigits = Array.from(String(numToSeparate), Number);
console.log(arrayOfDigits);
Example 3: number to array js
const arrayOfDigits = numToSeparate.toString().split("");