

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I convert a string into an integer in JavaScript?
The parseInt() method in JavaScript converts a string into a number. The method returns NaN if the value entered cannot be converted to a number.
Example
You can try to run the following code to convert a string into an integer −
<!DOCTYPE html> <html> <body> <button onclick = "display()">Check</button> <p id = "demo"></p> <script> function display() { var val1 = parseInt("50") + "<br>"; var val2 = parseInt("52.40") + "<br>"; var val3 = parseInt(" 75 ") + "<br>"; var res = val1 + val2 + val3; document.getElementById("demo").innerHTML = res; } </script> </body> </html>
- Related Questions & Answers
- How do I convert an integer to binary in JavaScript?
- How to convert a string into integer in JavaScript?
- How do I convert a double into a string in C++?
- How to convert a string vector into an integer vector in R?
- How to convert an array into JavaScript string?
- How to convert Python DateTime string into integer milliseconds?
- How to convert an integer into a date object in Python?
- How to convert a string of any base to an integer in JavaScript?
- How do I search through an array using a string, which is split into an array with JavaScript?
- Java Program to convert an integer into binary
- Convert an integer to a hex string in C++
- How to convert an integer to a hexadecimal string in Python?
- How to convert an integer to a octal string in Python?
- How to convert a JSON string into a JavaScript object?
- How do I turn a list into an array in Java?
Advertisements