The simplest way would be to use the native Number function:

var x = Number("1000")

If that doesn't work for you, then there are the parseInt, unary plus, parseFloat with floor, and Math.round methods.

parseInt()

var x = parseInt("1000", 10); // You want to use radix 10
    // So you get a decimal number even with a leading 0 and an old browser ([IE8, Firefox 20, Chrome 22 and older][1])

Unary plus

If your string is already in the form of an integer:

var x = +"1000";

floor()

If your string is or might be a float and you want an integer:

var x = Math.floor("1000.01"); // floor() automatically converts string to number

Or, if you're going to be using Math.floor several times:

var floor = Math.floor;
var x = floor("1000.01");

parseFloat()

If you're the type who forgets to put the radix in when you call parseInt, you can use parseFloat and round it however you like. Here I use floor.

var floor = Math.floor;
var x = floor(parseFloat("1000.01"));

round()

Interestingly, Math.round (like Math.floor) will do a string to number conversion, so if you want the number rounded (or if you have an integer in the string), this is a great way, maybe my favorite:

var round = Math.round;
var x = round("1000"); // Equivalent to round("1000", 0)
Answer from Nosredna on Stack Overflow
🌐
CodeChef
codechef.com › practice › course › strings › STRINGS › problems › TITLECASE
Convert String to Title Case Practice Problem in Strings
Test your knowledge with our Convert String to Title Case practice problem. Dive into the world of strings challenges at CodeChef.
🌐
W3Schools
w3schools.com › jsref › jsref_parseint.asp
JavaScript parseInt() Method
The parseInt method parses a value as a string and returns the first integer. A radix parameter specifies the number system to use: 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal. If radix is omitted, JavaScript assumes radix 10. If the value begins with "0x", JavaScript assumes radix 16. If the first character cannot be converted, NaN is returned.
Discussions

How can I convert a string to an integer in JavaScript? - Stack Overflow
So if you have noticed parseInt ... suitable if you want to retain the values after decimals. Use parseInt if and only if you are sure that you want the integer value. ... The question was "How do I convert a String into an integer in javascript" 2015-09-02T14:08:16.3... More on stackoverflow.com
🌐 stackoverflow.com
Convert string to number

parseInt can ignore non-numeric characters after a number, but not before. If there's anything before, such as a double quote character, parseInt will return NaN. Given your input, you would need to do something like use replace to massage it to work with parseInt

More on reddit.com
🌐 r/learnjavascript
6
2
January 23, 2019
Convert string to Integer in a JSON file
Array.map and Number More on reddit.com
🌐 r/learnjavascript
6
4
December 8, 2020
The unary + operator is a shortcut to convert a string into a number 🤩
Neat. Don't do this. More on reddit.com
🌐 r/webdev
282
999
March 31, 2018
🌐
W3Schools
w3schools.com › js › js_type_conversion.asp
JavaScript Type Conversions
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 › parseInt
parseInt() - JavaScript | MDN
The parseInt function converts its first argument to a string, parses that string, then returns an integer or NaN. If not NaN, the return value will be the integer that is the first argument taken as a number in the specified radix. (For example, a radix of 10 converts from a decimal number, ...
Top answer
1 of 16
3113

The simplest way would be to use the native Number function:

var x = Number("1000")

If that doesn't work for you, then there are the parseInt, unary plus, parseFloat with floor, and Math.round methods.

parseInt()

var x = parseInt("1000", 10); // You want to use radix 10
    // So you get a decimal number even with a leading 0 and an old browser ([IE8, Firefox 20, Chrome 22 and older][1])

Unary plus

If your string is already in the form of an integer:

var x = +"1000";

floor()

If your string is or might be a float and you want an integer:

var x = Math.floor("1000.01"); // floor() automatically converts string to number

Or, if you're going to be using Math.floor several times:

var floor = Math.floor;
var x = floor("1000.01");

parseFloat()

If you're the type who forgets to put the radix in when you call parseInt, you can use parseFloat and round it however you like. Here I use floor.

var floor = Math.floor;
var x = floor(parseFloat("1000.01"));

round()

Interestingly, Math.round (like Math.floor) will do a string to number conversion, so if you want the number rounded (or if you have an integer in the string), this is a great way, maybe my favorite:

var round = Math.round;
var x = round("1000"); // Equivalent to round("1000", 0)
2 of 16
306

Try parseInt function:

var number = parseInt("10");

But there is a problem. If you try to convert "010" using parseInt function, it detects as octal number, and will return number 8. So, you need to specify a radix (from 2 to 36). In this case base 10.

parseInt(string, radix)

Example:

var result = parseInt("010", 10) == 10; // Returns true

var result = parseInt("010") == 10; // Returns false

Note that parseInt ignores bad data after parsing anything valid.
This guid will parse as 51:

var result = parseInt('51e3daf6-b521-446a-9f5b-a1bb4d8bac36', 10) == 51; // Returns true
🌐
freeCodeCamp
freecodecamp.org › news › javascript-convert-string-to-number-js-string-to-int-example
JavaScript Convert String to Number – JS String to Int Example
November 7, 2024 - You can use the floor() method, which will round down the passed value to the nearest integer. The ceil() method, which is the opposite of floor(), rounds up to the nearest integer.
🌐
OpenReplay
blog.openreplay.com › convert-string-integer-javascript
How to Convert a String to an Integer in JavaScript
February 9, 2025 - The parseInt() function parses a string and returns an integer. It also allows specifying the number system (radix) for conversion. const str = ""42""; const number = parseInt(str, 10); console.log(number); // Output: 42 · The second argument, ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › convert-a-string-to-an-integer-in-javascript
Convert a String to an Integer in JavaScript - GeeksforGeeks
July 11, 2025 - The number() method converts a string into an integer number. It works similarly to the unary plus operator.
🌐
Better Programming
betterprogramming.pub › what-is-the-best-way-to-convert-a-string-to-a-number-in-javascript-67052a1706c6
The Best Way to Convert a String to a Number in JavaScript
March 6, 2020 - We begin with parseInt() which takes two arguments, a string and a radix. The function returns an integer parsed from the given string. If the first argument is not a string, it is converted to one automatically using ToString().
🌐
TutorialKart
tutorialkart.com › javascript › javascript-convert-string-to-integer
How to convert String to Integer in JavaScript?
September 23, 2021 - To convert a string to integer in JavaScript, call parseInt() function and pass the string as argument to it.
🌐
Favtutor
favtutor.com › articles › convert-string-to-number-javascript
Convert String to Number in JavaScript (6 Easy Methods)
November 20, 2023 - Math.ceil() rounds up to the nearest integer. So, 13.65 is rounded up to 14. We have obtained the desired result. The unary plus operator (+) is a simple and concise way to convert a string to a number in JavaScript.
🌐
Bacancy Technology
bacancytechnology.com › qanda › javascript › convert-string-to-integer-in-javascript
How to Convert String to Integer in JavaScript
August 5, 2025 - In JavaScript, you can convert a string to an integer using the following methods: let str = "123"; let num = parseInt(str); console.log(num); // 123 · let str = "123"; let num = +str; console.log(num); // 123 · let str = "123"; let num = Number(str); console.log(num); // 123 ·
🌐
Floyk
floyk.com › home › category › programming › how to convert string to integer in javascript
How to convert string to integer in JavaScript
March 24, 2022 - Making a conversion of integer to JavaScript is a common task for every frontend developer, and therefore there is many solutions for this small problem. ... var strToNum = parseFloat("65.12").toFixed(0) console.log(strToNum); // output => 65 // OR var strToNum = Math.floor(Number("65.12")) console.log(strToNum); // output => 65 · This method seems to be the fastest way to convert string to integer:
🌐
Timestamp Converter
timestamp.online
Timestamp Converter
Convert timestamp to date or date to timestamp easily. Learn how to convert timestamp to date in Python, PHP, JavaScript, Bash, ...
🌐
Epoch Converter
epochconverter.com
Epoch Converter - Unix Timestamp Converter
Epoch converter Batch converter Time zone converter Timestamp list LDAP converter WebKit/Chrome timestamp Unix hex timestamp Cocoa Core Data timestamp Mac HFS+ timestamp SAS timestamp Seconds/days since year 0 Bin/Oct/Hex converter Countdown in seconds Epoch clock · Week numbers Weeks by year Day numbers Days by year Years/leap years Calculate the difference between two dates · Routines by language Epoch in C Epoch in MySQL Epoch in PERL Epoch in PHP Epoch in JS/VBScript/ASP · Comments & questions Este sitio en Español Charset Tools
🌐
Altcademy
altcademy.com › blog › how-to-convert-a-string-to-a-number-in-javascript
How to convert a string to a number in JavaScript
June 9, 2023 - The parseInt() function is another built-in JavaScript function that can be used to convert a string to an integer.
🌐
Built In
builtin.com › articles › javascript-string-to-a-number
How to Convert a JavaScript String to Number | Built In
Below are several different methods you can use to convert a string into a number in JavaScript with example code. parseInt() parses a string and returns a whole number. Spaces are allowed. Only the first number is returned. This method has a limitation though. If you parse the decimal number, it will be rounded off to the nearest integer value and that value is converted to string.