How to split a number into an array in JavaScript

Array.from()

 

Use Array.from() to split a number into an array in JavaScript

By passing the number converted to a string as the first argument, and the Number constructor as the second following is an example

 

let number = 12345689;
arr = Array.from(String(number), Number);


another way 

let number = 12345689;
String(number).split('').map(Number);

 


Tags:

Share:

Related posts