I have this string:
items = "['item1', 'item2']"
i need it to be a javascript array like this:
items = ['item1', 'item2']
i try this and it works:
items.replace("]","").replace("[","").replaceAll("'","").split(",");
and the result I obtained was as expected:
['item1', 'item2']
The question is: can the same be done in a simpler way?
eval(items)orJSON.parse(items.replace(/'/g, '"'))eval: stackoverflow.com/questions/197769/…eval, butJSON.parseis the way to go for stuff like this.JSON.parse()to interpret the final result as JSON data.