65

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'

Elias Van Ootegem
  • 70,983
  • 9
  • 108
  • 145
RobKohr
  • 6,206
  • 7
  • 45
  • 64

0 Answers0