var arr1="11ab,22bc,33cd", arr2=['ab','bc','cd']; var replaceWords = function () { this.content = arr1; this.words = arr2; } replaceWords.prototype = { changeColor:function () { var len=this.words.length; for(var i=0;i<len;i++){ this.content = this.content.replace(new RegExp(this.words[i],'g'),this.words[i].split("").reverse().join("")); } return this.content; } } var arrNew =new replaceWords().changeColor(); console.log(arrNew);
JavaScript实例 - 替换字符串中指定的内容,replace
最新推荐文章于 2024-02-05 10:46:31 发布