Home > front end >  Js implementation replaceAll
Js implementation replaceAll

Time:12-11

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:

reference 1/f, the sky wave response:
with regular expressions is not directly by the
he is regular to String object hanging a method on the prototype

CodePudding user response:

refer to the second floor chenrynet response:
Quote: reference 1/f, the sky wave response:
with regular expressions is not directly by the
he is regular to hanging on a String object prototype method
positive solutions
  • Related