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
  • 74,482
  • 9
  • 111
  • 149
RobKohr
  • 6,611
  • 7
  • 48
  • 69

0 Answers0