I have a string called
var string ="Catch 22 Slaughterhouse 5 Fahrenheit 451"
I just want to print out the numbers from the string using the split function, array or loops in javascript
I have a string called
var string ="Catch 22 Slaughterhouse 5 Fahrenheit 451"
I just want to print out the numbers from the string using the split function, array or loops in javascript
You can use regular expression to extract numbers from the string.
\d
will match any number from the string. +
will match one or more of the preceding characters.
var str = "Catch 22 Slaughterhouse 5 Fahrenheit 451";
var numbers = str.match(/\d+/g);
document.write(numbers);