Sometimes, we want to remove numbers from a string with JavaScript.
In this article, we’ll look at how to remove numbers from a string with JavaScript.
How to remove numbers from a string with JavaScript?
To remove numbers from a string with JavaScript, we can use the string replace
method with a regex.
For instance, we write
const newQuestionText = questionText.replace(/[0-9]/g, "");
to call questionText.replace
with the /[0-9]/g
regex to match all numbers in the questionText
string.
Then we replace them all with empty strings.
Conclusion
To remove numbers from a string with JavaScript, we can use the string replace
method with a regex.