JavaScript Convert String to Integer


JavaScript Convert String to Integer – It is very simple to convert string to integer. There are various methods to convert a string into integer. Here in this tutorial we are going to explain how you can convert
string to integer using few most common methods. We will also present demo for each example.


JavaScript Convert String to Integer

You can convert string into integer using any one of the method –

Method 1 : Using parseInt()

This is most common method used to convert the strings into integer. This is the simple and best method to convert strings into the integer.

JavaScript Convert String to Integer Example:

var a = "10a"; // string
var resultInt = parseInt(a); // output as 10

Try it »

If you run the above example it will produce the output something like this –

JavaScript Convert String to Integer

Method 2 : Using Math.floor() function

You can also use Math.floor() function to convert strings into the integer.

JavaScript Convert String to Integer Example:

var a = "10.09"; // string
var resultInt = Math.floor(a); // output as 10

Try it »

If you run the above example it will produce the output something like this –

JavaScript Convert String to Integer Example


Advertisements

Add Comment

📖 Read More