You can use Array.map to convert each element into a number.

var a = "1,2,3,4";

var b = a.split(',').map(function(item) {
    return parseInt(item, 10);
});

Check the Docs


Or more elegantly as pointed out by User: thg435

var b = a.split(',').map(Number);

Where Number() would do the rest:check here


Note: For older browsers that don't support map, you can add an implementation yourself like:

Array.prototype.map = Array.prototype.map || function(_x) {
    for(var o=[], i=0; i<this.length; i++) { 
        o[i] = _x(this[i]); 
    }
    return o;
};
Answer from techfoobar on Stack Overflow
🌐
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 - To convert an array of strings to numbers using a for loop, iterate through each string, convert it to a number using Number(), and push it to a new array.
🌐
QuickRef.ME
quickref.me › home › how to convert an array of strings to numbers in javascript - quickref.me
How to convert an array of strings to numbers in JavaScript - QuickRef.ME
In this Article we will go through how to convert an array of strings to numbers only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
🌐
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
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.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-array-of-strings-to-array-of-numbers-in-javascript
How to convert array of strings to array of numbers in JavaScript?
The parseInt() method is a built-in function in JavaScript that takes a string as an argument and returns a number. This method can be used to convert an array of strings to an array of numbers.
🌐
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 = [...
🌐
Codecademy
codecademy.com › forum_questions › 55ac0f8fe39efe887500021c
Arrays: How can array have string and number(together)??? | Codecademy
42 is a number literal, as “some string data” is a string literal, {} is an object literal, [] is an array literal. I still think of numbers and strings as primitives, and accept them as literal once they have a wrapper object. This is as far as I’ll go with this concept. Now let’s focus on values and the myriad expressions that yield them. ... All of the above are expressions. They all yield a value (in this case, 42). That is what expressions do in JavaScript…
Find elsewhere
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-convert-a-string-of-numbers-to-an-array-of-numbers-in-javascript-ab07ec0d3f6d
How to Convert a String of Numbers to an Array of Numbers in JavaScript? | by John Au-Yeung | JavaScript in Plain English
May 27, 2021 - We can use the split method available with JavaScript strings to convert a string into an array of strings by splitting the string by a separator. So we can use the split method to split the string into an array of strings by the commas.
🌐
W3Schools
w3schools.com › js › js_type_conversion.asp
JavaScript Type Conversions
The global method Number() converts a variable (or a value) into a number. A numeric string (like "3.14") converts to a number (like 3.14).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number
Number - JavaScript | MDN
There is no separate integer type in common everyday use. (JavaScript also has a BigInt type, but it's not designed to replace Number for everyday uses. 37 is still a number, not a BigInt.) When used as a function, Number(value) converts a string or other value to the Number type.
🌐
Built In
builtin.com › articles › javascript-string-to-a-number
How to Convert a JavaScript String to Number | Built In
I prefer to use the Number() method because it’s easier for developers to read the code, and it’s quite intuitive to realize that it’s converting a string to Number. Performance chart rating each method to convert a javascript string to a number.
🌐
Dead Simple Chat
deadsimplechat.com › blog › 5-ways-to-convert-string-to-a-number-in-javascript
5 Ways to Convert String to a Number in JavaScript
July 6, 2024 - Example in JavaScript using the Number() function · Implicit Type Conversion: JavaScript programming language also does type conversion automatically based on the context of the operation. This is called as implicit type conversion as the developer is not explicitly type converting the value. Using the == operator to compare a String and a Number, it is an example of implicit type conversion
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › from
Array.from() - JavaScript | MDN
Python, Clojure, etc.) const range = (start, stop, step) => Array.from( { length: Math.ceil((stop - start) / step) }, (_, i) => start + i * step, ); // Generate a sequence of numbers from 0 (inclusive) to 5 (exclusive), incrementing by 1 range(0, 5, 1); // [0, 1, 2, 3, 4] // Generate a sequence of numbers from 1 (inclusive) to 10 (exclusive), incrementing by 2 range(1, 10, 2); // [1, 3, 5, 7, 9] // Generate the Latin alphabet making use of it being ordered as a sequence range("A".charCodeAt(0), "Z".charCodeAt(0) + 1, 1).map((x) => String.fromCharCode(x), ); // ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-convert-a-javascript-string-into-an-array-of-integers-5ad8e2ed4435
How to Convert a JavaScript String into an Array of Integers? | by John Au-Yeung | JavaScript in Plain English
April 10, 2025 - To do that, we call split with a space string to split the string by its spaces and put the split strings into an array. Then we call map with Number to convert all the values into numbers.
🌐
W3Schools
w3schools.com › js › js_number_methods.asp
JavaScript Number Methods
The methods above are not number methods. They are global JavaScript methods. The Number() method can be used to convert JavaScript variables to numbers: