
Improve Article
Save Article
The number from a string in javascript can be extracted into an array of numbers by using the match method. This function takes a regular expression as an argument and extracts the number from the string. Regular expression for extracting a number is (/(\d+)/).
Example 1: This example uses match() function to extract numbers from strings.
html
|
Output:

Extract a number from a string
Example 2: This example uses the match() function to extract numbers from strings.
html
|
Output:

Extract a number from a string
Example 3: This example uses reduce method to extract all the numbers from the string.
HTML
|
Output:

Extract a number from a string
JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You
can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.