Convert string to integer in JavaScript
In this tutorial, you are given a string value. You should convert the string to an integer type value.
Solution
To convert a given string into integer, use JavaScript global function parseInt()
. Pass the string as argument to parseInt()
function, and the function returns the integer value.
Program
str
is the given string value. we use parseInt()
method to parse the string str
into an integer.
let str = "45";
let num = parseInt(str);
console.log(num);
console.log(typeof(num));