I am in search of a way to transform a string, such as: "one, two, three, four"
into a string like:
"["one", "two", "three", "four"]"
I have been attempting to devise a solution that addresses most scenarios, but so far, I have not been successful. The approach I have taken thus far is as follows:
var splitString = <mystring>.split(', ');
var stringWithQuotes = `"` + stringSplit.join(`", "`) + `"`;
However, if the input is formatted as "one,two,three,four"
(without spaces), the string will not be split correctly. Additionally, the square brackets are missing from the output as well.
Do you have any suggestions for how this issue can be resolved?