Add the prototype method
String. The prototype. The replaceAll=function (s1, s2) {return this. The replace (new RegExp (s1, "gm"), s2);
}
Var STR="aaa".
Var str2=STR. ReplaceAll (" aaa ", "BBB");
The console. The log (str2);//"BBB"
CodePudding user response:
It is good to use regular expressions to not directly
CodePudding user response: