How to remove numbers from a string?

前端 未结 7 1676
遇见更好的自我
遇见更好的自我 2020-12-12 19:56

I want to remove numbers from a string:

questionText = \"1 ding ?\"

I want to replace the number 1 number and the question mar

7条回答
  •  时光取名叫无心
    2020-12-12 20:36

    You're remarkably close.

    Here's the code you wrote in the question:

    questionText.replace(/[0-9]/g, '');
    

    The code you've written does indeed look at the questionText variable, and produce output which is the original string, but with the digits replaced with empty string.

    However, it doesn't assign it automatically back to the original variable. You need to specify what to assign it to:

    questionText = questionText.replace(/[0-9]/g, '');
    

提交回复
热议问题