我想搜索一个函数可以替换所有"?"在一个字符串中按位置排列数组,如下面的语法:
replace("WHERE id > ? AND id < ?",[10, 20]);
输出的将是:
"WHERE id > 10 AND id < 20"
答案 0 :(得分:0)
我认为它与此链接相同
Replace multiple strings at once
var find = "WHERE id > $ AND id < $";
var replace = [10, 20] ;
String.prototype.replaceArray = function(find, replace) {
var replaceString = this;
var regex;
for (var i = 0; i < find.length; i++) {
regex = new RegExp(find[i], "$");
replaceString = replaceString.replace(regex, replace[i]);
}
return replaceString;
};