integer 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 n = 123456;
Array.from(n.toString()).map(Number);
// [1, 2, 3, 4, 5, 6]
Also in JavaScript:
- return an array of strings from an array of objects js
- jquery delete buton
- eliminare spazi inizio e fine stringa javascript
- js filter text
- javascript in viewport
- js clone deep
- how to make a circle in js
- generate random character in javascript
- how to make graphql request in axios
- how to make a var and sprite in javascript
- how to get utc time in angular
- javascript pass iterator to callback
- JSONDecoder
- node red reverse proxy for ui to root
- sort by ascending javascript
- restful react npm
- detect scroll javascript
- short string javascript
- react native AsyncStorage
- oop js is
- Vue is not defined
- element.classname javascript
- element.value javascript
- react environment variables