How to convert a javascript array in a string separated by comma
Posted on April 14, 2024
The title is pretty self explanatory, here the code:
const myArray = ['a', 'b', 'c']
JSON.stringify(myArray).replace(/[\[\]]/mig, '')
// '"a","b","c"'
Here an (better) alternative given by ChatGPT:
myArray.map(item => `"${item}"`).join(',');