Javascript multiple replace

JavascriptRegexStringReplace

Javascript Problem Overview


How do you replace all instances of one string with another in javascript? Example:

someString = 'the cat looks like a cat'
anotherString = someString.replace('cat', 'dog');

results in anotherString being set to 'the dog looks like a cat', and I would like it to be 'the dog looks like a dog'

Javascript Solutions


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobKohrView Question on Stackoverflow