var array = {"from1":"to1", "from2":"to2"}
for (var val in array)
text = text.replace(new RegExp(val, "g"), array[val]);
Edit: As Andy said, you may have to escape the special characters using a script like this one.
More Related Contents:
- How to replace all occurrences of a string in JavaScript
- How do I replace a character at a particular index in JavaScript?
- Replace multiple strings with multiple other strings
- 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
- RegEx for match/replacing JavaScript comments (both multiline and inline)
- Remove whitespace and line breaks between HTML elements using jQuery
- Replace a Regex capture group with uppercase in Javascript
- How to replace last occurrence of characters in a string using javascript
- How can I replace a regex substring match 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
- How to trim a file extension from a String in JavaScript?
- JavaScript replace/regex
- Efficient Javascript String Replacement
- how to clear or replace a cached image
- Insert space before capital letters
- How can I perform a str_replace in JavaScript, replacing text in JavaScript?
- Replace a string in a file with nodejs
- JavaScript – Replace all commas in a string [duplicate]
- Reformat string containing date with Javascript
- 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
- Javascript – Replacing the escape character in a string literal
- JavaScript: replace last occurrence of text in a string