Skip to content
Advertisement

How to remove numbers from a string?

I want to remove numbers from a string:

JavaScript

I want to replace the number 1 number and the question mark ?. It can be any number. I tried the following non-working code.

JavaScript

Advertisement

Answer

Very close, try:

JavaScript

replace doesn’t work on the existing string, it returns a new one. If you want to use it, you need to keep it!
Similarly, you can use a new variable:

JavaScript

One last trick to remove whole blocks of digits at once, but that one may go too far:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement