var str = "dogdogdog"; var str2 = str.replace(/dog/g,"cat"); console.log(str2);
参考:https://blog.csdn.net/fukaiit/article/details/83245943