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
原文地址:https://www.cnblogs.com/liushunli/p/10083730.html