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);const numToSeparate = 12345;
const arrayOfDigits = Array.from(String(numToSeparate), Number);
console.log(arrayOfDigits); //[1,2,3,4,5]const arrayOfDigits = numToSeparate.toString().split("");
Also in JavaScript:
- how to remove last element in js
- log javascript
- update angular cli
- how to remove an object from array in react native
- how to export csv file in angularjs
- how to make a css clock
- loop in javascript
- react if statement
- check the doc name in javascript
- how to find the smallest two numbers in an array javascript
- javascript founder
- js shuffle array
- diff two arrays javascript
- span change jquery
- jQuery exclude exteranl link for images
- refresh javascript using require
- bootstrap in javascript
- node send file
- moving a item fro index to another index, javascript
- creating a 2d array in js
- nodemon.json env
- refresh after delete in express
- get today date and time in js
- ionic ngfor in component