replace 重写

String.prototype.myReplace = function (f, e) {//把f替换成e
var reg = new RegExp(f, "g"); //创建正则RegExp对象
return this.replace(reg, e);
}

 

 

let str = "2018-8-14";

str.myReplace('-','/')//2018-8-14

posted on 2018-12-07 16:40  刘顺利  阅读(224)  评论(0编辑  收藏  举报

导航