Javascript - how to replace a sub-string?

后端 未结 4 2131
长情又很酷
长情又很酷 2021-02-19 16:37

This is a simple one. I want to replace a sub-string with another sub-string on client-side using Javascript.

Original string is \'original READ ONLY\'

4条回答
  •  情话喂你
    2021-02-19 17:33

    I prefer the regex approach,

    newstring = oldstring.replace(/regexforstringtoreplace/, 'new string');

    its also worth considering the g and i regex modifiers, these do a global replace (i.e. replaces all occurrences) and makes it case insensitive.

    for example:

    
    

提交回复
热议问题