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.
More Related Contents:
- Reformat string containing date with Javascript
- How to replace all occurrences of a string in JavaScript
- How do I replace a character at a particular index in JavaScript?
- Fastest method to replace all instances of a character in a string [duplicate]
- Replace multiple strings at once
- How to replace all occurrences of a string in JavaScript
- Using jQuery to replace one tag with another
- How can I remove a character from a string using JavaScript?
- RegEx for match/replacing JavaScript comments (both multiline and inline)
- Replace a Regex capture group with uppercase in Javascript
- JavaScript .replace only replaces first Match [duplicate]
- How can I replace a regex substring match in Javascript?
- Case insensitive string replacement in JavaScript?
- Stop cursor from jumping to end of input field in javascript replace
- How do I replace all occurrences of a string in JavaScript?
- Javascript and backslashes replace
- JavaScript replace/regex
- Efficient Javascript String Replacement
- how to clear or replace a cached image
- Replace a string in a file with nodejs
- JavaScript – Replace all commas in a string [duplicate]
- Why can’t I use accented characters next to a word boundary?
- JavaScript replace \n with [duplicate]
- `string.replace` doesn’t change the variable [duplicate]
- How do I replace all occurrences of “/” in a string with “_” in JavaScript?
- Replace spaces with dashes and make all letters lower-case
- How to replace curly quotation marks in a string using Javascript?
- Javascript – Replacing the escape character in a string literal
- javascript replace globally with array
- JavaScript: replace last occurrence of text in a string