JavaScript------自定义string.replaceAll()方法

代码::

注意:原始的replace()方法只能替换第一个字符串check

String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}

var data = "check out,check in";
var li = data.replaceAll('check','checked');
原文地址:https://www.cnblogs.com/tianhengblogs/p/7050925.html