How do I convert a double quote array to single quotes

how do I convert a double quote array to single quotes?

input:
[ 18 , "test" , "test123" ]

Output:
[ 18 , 'test' , 'test123' ]

Why do you need to change that?

I want to create an insert want in Microsoft SQL
with double quotes an error occurs

My array =
return Object.values(item.body)

INSERT table_name 
(param1, param2, param3)
VALUES(18, 'test', 'test123')  -- my array


Hi @leosantosx

Object.values(item.body).join() seems to don’t add quotes around your values, maybe you should add them by yourself

1 Like

Perhaps, you can do replace(/'/g, '\"') to the result.

Solution:

let str = ''
Object.values(item.body).forEach(i => {
    str += "'" + i + "',";
}) 
return `INSERT ${item.headers.database}
(${Object.keys(item.body).join()}) 
VALUES(${str.substring(0, str.length - 1)})`
1 Like