As shown below:
var str = 'abcadeacf';var str1 = str.replace('a', 'o');alert(str1); // Print result: obcadeacfvar str2 = str.replace(/a/g, 'o');alert(str2); // Print result: obcodeocf,Note: The first parameter of replace here is a regular expression, and /g is the full text matching identifier.
The above method of replacing all the specified characters in the string in js replace(a,b) is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.