Answers for "how to convert number to array in javascript using Array.from"

3

turn number into array javascript

const myNumber = 1245;
function numberToArray(number) {
  	let array = number.toString().split("");//stringify the number, then make each digit an item in an array
  	return array.map(x => parseInt(x));//convert all the items back into numbers
}
//use the function
var myArray = numberToArray(myNumber);
Posted by: Guest on April-02-2020
0

how to convert number to array in javascript using Array.from

const n = 123456;
Array.from(n.toString()).map(Number);
// [1, 2, 3, 4, 5, 6]
Posted by: Guest on February-23-2021
0

number to array javascript

const n = 123456;
Array.from(n.toString()).map(Number);
// [1, 2, 3, 4, 5, 6]
Posted by: Guest on October-27-2020
2

number to array js

const arrayOfDigits = numToSeparate.toString().split("");
Posted by: Guest on June-19-2020

Code answers related to "how to convert number to array in javascript using Array.from"

Code answers related to "Javascript"

Browse Popular Code Answers by Language