标签:his type return bsp cti reg nbsp prototype this
String.prototype.format=function(){ if(arguments.length===0){ return String(this); } let reg=/(\{\d\})/; let r=this; while(reg.test(r)){ let index=RegExp.$1.slice(1,-1); r = r.replace(new RegExp("\\{"+index+"\\}","g"),(index >= arguments.length)?"":arguments[index]); } return r; };
Javascript字符串占位符替换
》"你好,我是{0},今年{2}岁,性别为{1},测试结束".format(‘恶魔‘,‘男‘,‘18‘)
《 你好,我是恶魔,今年18岁,性别为男,测试结束
标签:his type return bsp cti reg nbsp prototype this
原文地址:https://www.cnblogs.com/XingXiaoMeng/p/11647206.html