ECMAScript5 provides a map method for Arrays, applying a function to all elements of an array. Here is an example:

var a = ['1','2','3']
var result = a.map(function (x) { 
  return parseInt(x, 10); 
});

console.log(result);

See Array.prototype.map()

Answer from dheerosaur on Stack Overflow
๐ŸŒ
Designcise
designcise.com โ€บ web โ€บ tutorial โ€บ how-to-convert-an-integer-to-an-array-of-digits-in-javascript
Converting Integer to an Array of Digits in JavaScript - Designcise
October 1, 2022 - Adding the minus sign (-) as a string means that in the resulting array, if the original number is negative, the first element of the array will have the minus sign as a string: ... To convert an integer (positive or negative) in this way, to an array of digits, you can follow these steps:
Discussions

javascript - How to convert an integer into an array of digits - Stack Overflow
I have fist convert the number to a string and then used Array.from() to convert the string to an array. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to convert all the items in a String array to Numbers?
Hello! I am trying to convert an array that contains string values to Numbers, so the array contains something like array = [0: "5", 1:"15", 2:"0", 3:"30"] This array is also a value coming from a transformer, so transformer1.value returns the array above. Now, I need to convert all the values ... More on community.retool.com
๐ŸŒ community.retool.com
1
0
June 2, 2022
How do I separate an integer into separate digits in an array in JavaScript? - Stack Overflow
113 JavaScript Number Split into individual digits ... 2 Is there a simple way to split a number into an array of digits without converting it to a string and back? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert number into array in Javascript - Stack Overflow
When I type a number with prompt var myNumber = parseInt(prompt("..."))I want it to be converted into an array of numbers. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Top answer
1 of 16
128

**** 2019 Answer ****

This single line will do the trick:

Array.from(String(12345), Number);

Example

const numToSeparate = 12345;

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

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

Explanation

1- String(numToSeparate) will convert the number 12345 into a string, returning '12345'

2- The Array.from() method creates a new Array instance from an array-like or iterable object, the string '12345' is an iterable object, so it will create an Array from it.

3- In the process of creating this new array, the Array.from() method will first pass any iterable element (ex: '1', '2') to the callback we declare as a second parameter (which is the Number function in this case). This is possible because an String is an "array-like" object. To make it simpler, we could've declared the callback as: Array.from(String(numToSeparate), n => Number(n)

4- The Number function will take any string character and will convert it into a number eg: Number('1'); will return 1.

5- These numbers will be added one by one to a new array and finally this array of numbers will be returned.

Summary

The code line Array.from(String(numToSeparate), Number); will convert the number into a string, take each character of that string, convert it into a number and put in a new array. Finally, this new array of numbers will be returned.

2 of 16
33

I'd go with

var arr = n.toString(10).replace(/\D/g, '0').split('').map(Number);

You can omit the replace if you are sure that n has no decimals.

๐ŸŒ
Retool
community.retool.com โ€บ ๐Ÿ’ฌ queries and resources
How to convert all the items in a String array to Numbers? - ๐Ÿ’ฌ Queries and Resources - Retool Forum
June 2, 2022 - Hello! I am trying to convert an array that contains string values to Numbers, so the array contains something like array = [0: "5", 1:"15", 2:"0", 3:"30"] This array is also a value coming from a transformer, so transformer1.value returns the array above. Now, I need to convert all the values inside the array to numbers so I can do math operations with them So far I tried a loop like this var data = {{ transformer1.value }} //this is the transformer that contains the array var Minutes = [...
๐ŸŒ
W3Resource
w3resource.com โ€บ javascript-exercises โ€บ fundamental โ€บ javascript-fundamental-exercise-7.php
JavaScript fundamental (ES6 Syntax): Converts a specified number to an array of digits - w3resource
July 3, 2025 - // Define a function called `digitize` that takes a number `n`. const digitize = n => // Convert the number to a string, then split it into an array of characters. [...`${n}`] // Map each character to its corresponding integer value.
๐ŸŒ
Medium
medium.com โ€บ programming-essentials โ€บ how-to-convert-an-integer-to-an-array-of-digits-in-javascript-fad690b3a2e5
How to Convert an Integer to an Array of Digits in JavaScript | by Cristian Salcescu | Frontend Essentials | Medium
August 29, 2021 - The Number built-in in function can transform any value into a number. ... The map array method transforms an array of values into a new array of transformed values using a mapping function. Below is an example of transforming anโ€ฆ ... Learn more on JavaScript, functional programming, and front-end development.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-convert-a-number-into-an-array-in-javascript
How to convert a number into an array in JavaScript?
March 2, 2023 - In this example, we first convert the number to a string using the toString() method. Then we use a for loop to iterate over the number and use the parseInt method to convert the individual digits and push it into the array.
๐ŸŒ
IQCode
iqcode.com โ€บ code โ€บ javascript โ€บ how-to-convert-number-to-array-in-javascript-using-arrayfrom
how to convert number to array in javascript using Array.from Code Example
October 22, 2021 - const myNumber = 1245; function numberToArray(number) { let array = number.toString().split("");//stringify the number, then ma...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-convert-a-number-into-array-in-javascript
JavaScript โ€“ Convert a Number into JS Array | GeeksforGeeks
Another approach to convert a number into an array in JavaScript is by using the split() method directly on the string representation of the number.
Published ย  January 10, 2025
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ from
Array.from() - JavaScript - MDN Web Docs
A new Array instance. ... To convert an ordinary object that's not iterable or array-like to an array (by enumerating its property keys, values, or both), use Object.keys(), Object.values(), or Object.entries().
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ convert-number-to-reversed-array-of-digits-javascript
Convert number to reversed array of digits JavaScript
March 27, 2023 - Letโ€™s say, we have to write a ... but in reverse order. We will convert the number into a string, then split it to get an array of strings of digit, then we will convert the string into numbers, reverse the array and finally return it....
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-convert-array-of-strings-to-array-of-numbers-in-javascript
How to convert array of strings to array of numbers in JavaScript?
September 15, 2023 - In JavaScript, there are different ways to convert an array of strings to an array of numbers. The first way is to use the built-in parseInt() method, and the second way is to use a type conversion function, and the third one is to use the unary +
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-convert-array-of-strings-to-array-of-numbers
Convert Array of Strings to Array of Numbers in JavaScript | bobbyhadz
March 2, 2024 - The Array.map method doesn't change the contents of the original array, it returns a new array. You can also use the Number() constructor and the unary plus (+) operator to convert a string to a number.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-convert-array-of-strings-to-array-of-numbers-in-javascript
How to convert array of strings to array of numbers in JavaScript ? - GeeksforGeeks
July 23, 2025 - // Create an array of string let stringArray = ["1", "2", "3", "4", "5"]; // Create an empty array of number let numberArray = []; // Store length of array of string // in letiable length length = stringArray.length; // Iterate through array of string using // for loop // push all elements of array of string // in array of numbers by typecasting // them to integers using parseInt function for (let i = 0; i < length; i++) // Instead of parseInt(), Number() // can also be used numberArray.push(parseInt(stringArray[i])); // Print the array of numbers console.log(numberArray); ... Javascript map()
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-convert-integer-array-to-string-array-using-javascript
How to convert Integer array to String array using JavaScript ? | GeeksforGeeks
July 29, 2024 - Falsy/Falsey Values: In JavaScript, there are 7 falsy values, which are given below falsezero(0,-0)empty string("", ' ' , ` `)BigIntZero(0n,0x0n)nullundefinedNaNIn JavaScript, the array accepts all types of falsy values. Let's see some approaches on how we can remove falsy values from an array in Ja ... Here are the different methods to swap variables using arrays in JavaScript1.