如何在Javascript数组中替换单引号而不是双引号? [英] How to replace single quotes instead of double quotes in array of Javascript?
本文介绍了如何在Javascript数组中替换单引号而不是双引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带双引号的字符串值数组,我想要的只是将带单引号的数组字符串值转换。
I have an array of string values with double quotes all i want is convert the array string value with single quotes.
Var arr=["abc123","cde345","ijk789"];
var test=[]
for(var i=0;i<arr.length;i++){
ans=arr[i].replace(/"/g,"'")
test.push(ans)
}
测试结果应该是['abc123','cde345','ijk789']
The test result supposed to be ['abc123','cde345','ijk789']
推荐答案
您可以使用单个
var array = ["abc123", "cde345", "ijk789"],
list = array.map(s => `'${s}'`).join(', ');
console.log(`select * from tableName where id in (${list})`);
这篇关于如何在Javascript数组中替换单引号而不是双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文