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)
}
The test result supposed to be ['abc123','cde345','ijk789']
You could map the items with single quotes for a list and join it with comma.
var array = ["abc123", "cde345", "ijk789"], list = array.map(s => `'${s}'`).join(', '); console.log(`select * from tableName where id in (${list})`);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.