I'm trying to replace multiple words in a string with multiple other words. The string is "I have a cat, a dog, and a goat."
However, this does not produce "I have a dog, a goat, and a cat", but …
I understand that doing something like
var a = "hello";
a += " world";
It is relatively very slow, as the browser does that in O(n) . Is there a faster way of doing so without installing new libraries?