convert number to 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]Array.from(String(12345), Number);const arrayOfDigits = numToSeparate.toString().split("");
Also in JavaScript:
- javascript enumerate with index
- child process spawn python node js
- array reduce
- loop async javascript
- how to read json file with gluegun
- take out decoration from link react
- how to add json data to xmlhttprequest
- railsparse json to object
- dustjs compilator
- how to use a js class in react
- jstree select all visible node only
- TextInput disable react native
- Javascript get caller function
- update node mac to specific version
- how to add links in react js
- js remove item array
- ajax data post call in javascript
- WHAT IS NODE IN DOM
- remove in javascript
- most popular company with nodejs
- moving a item fro index to another index, javascript
- how to trigger an event on reload js
- hello
- afficher une variable dans la console javascript