Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
Comment

convert number to array javascript

const numToSeparate = 12345;

const arrayOfDigits = Array.from(String(numToSeparate), Number);

console.log(arrayOfDigits);   //[1,2,3,4,5]
Comment

number to array javascript

const n = 123456;
Array.from(n.toString()).map(Number);
// [1, 2, 3, 4, 5, 6]
Comment

number to array js

const arrayOfDigits = numToSeparate.toString().split("");
Comment

PREVIOUS NEXT
Code Example
Javascript :: polyfill for apply 
Javascript :: p5.js add class to button 
Javascript :: local storage size check 
Javascript :: javascript substring after character 
Javascript :: how to code number must be smaller than in javascript 
Javascript :: append sibling javascript after first child 
Javascript :: find element in array javascript 
Javascript :: regex ranges 
Javascript :: create phone number javascript 
Javascript :: js do every x seconds 
Javascript :: javascript last index 
Javascript :: js replace characters in a string 
Javascript :: jquery remove keypress event 
Javascript :: react typewriter 
Javascript :: react native use navigation outside component 
Javascript :: last item in object javascript 
Javascript :: moment add seconds 
Javascript :: javascript regex extract url from string 
Javascript :: string contains javascirpt 
Javascript :: a <route is only ever to be used as the child of <routes element" 
Javascript :: javascript character count 
Javascript :: copy localstorage javascript 
Javascript :: javascript object array iteration 
Javascript :: router.query is undefined in first render 
Javascript :: js check if objects have same values 
Javascript :: react native image source local file 
Javascript :: pipe of date angular 
Javascript :: how to check if radio button is checked javascript 
Javascript :: jquery set a value in td 
Javascript :: dayjs timezone 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =