How can I perform a str_replace in JavaScript, replacing text in JavaScript?

后端 未结 22 1862
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 00:29

I want to use str_replace or its similar alternative to replace some text in JavaScript.

var text = \"this is some sample text that i want to re         


        
22条回答
  •  春和景丽
    2020-12-01 01:03

    You would use the replace method:

    text = text.replace('old', 'new');
    

    The first argument is what you're looking for, obviously. It can also accept regular expressions.

    Just remember that it does not change the original string. It only returns the new value.

提交回复
热议问题