
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to get a number value of a string in Javascript?
To get an integer in the string “abcde 30”, use the following regex in JavaScript, else it will return NaN. With that, use parseInt() to get the numbers with regex under String match() method −
Example
<!DOCTYPE html> <html> <body> <script> var myStr = "abcdef 30"; var num = parseInt(myStr.match(/\d+/)) alert(num); </script> </body> </html>
- Related Articles
- How to get a string representation of a number in JavaScript?
- How to get a number of vowels in a string in JavaScript?
- How to get the absolute value of a number in JavaScript?
- How to get the primitive value of string in Javascript?
- How to get the value of a number rounded to the nearest integer in JavaScript?
- How to get the length of a string in JavaScript?
- How to convert a boolean value to string value in JavaScript?
- How to get the last index of an occurrence of the specified value in a string in JavaScript?
- How to get the first index of an occurrence of the specified value in a string in JavaScript?
- How to get the cosine of a number in JavaScript?
- How to get the sine of a number in JavaScript?
- How to get the tangent of a number in JavaScript?
- How to get the length of a Number in JavaScript?
- How to convert a value to a number in JavaScript?
- How to Get Current Value of a CSS Property in JavaScript?

Advertisements