Reputation: 181
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']
Upvotes: 1
Views: 4506
Reputation: 386654
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})`);
Upvotes: 3